0
我正在測試我的vuejs組件,併發生了一個非常奇怪的問題。期望方法讀取錯誤的值wrapper.vm.shown
這裏是我的測試
import { mount } from 'avoriaz';
let wrapper = mount(MyComponent, { globals: {$route},});
it('the click changes the value of shown',() => {
// This passes
expect(wrapper.vm.shown).to.equal(false);
// the click on this element will turn shown value into true
wrapper.first('#my_link').trigger('click');
// the value of shown is indeed true now
console.log(wrapper.vm.shown); // LOG LOG: true
expect(wrapper.vm.shown).to.equal(true); // expected undefined to equal true
});
發生了什麼事,爲什麼shown
當作爲參數傳遞給expect
方法是undefined
並通過console.log
顯示時是布爾?
很好! thx,[$ nextTick](https://vuejs.org/v2/guide/reactivity.html#Async-Update-Queue) – smarber