I am reading the following book Testing Vue js application
the code
<template>
<div
:class="{ hidden: isHidden}"
:style="{
width: '0%',
}"
/>
</template>
<script>
export default {
data() {
return {
isHidden: true,
}
},
methods: {
start() {
this.isHidden = false;
},
finish() {},
},
};
</script>
the test
test('displays the bar when start is called', () => {
const wrapper = mount(ProgressBar)
expect(wrapper.classes()).toContain('hidden')
wrapper.vm.start()
expect(wrapper.classes()).not.toContain("hidden");
})
The test must be passed according to the book but in my case, it does not and I get the following error
expect(array).not.toContain(value)
Expected array:
["hidden"]
Not to contain value:
"hidden"
21 | // nextTick is used cuz the dom update is happing async
22 | // wrapper.vm.$nextTick(() => {
> 23 | expect(wrapper.classes()).not.toContain("hidden");
| ^
24 | // });
25 |
26 | })
but when I nextTick like the following the test passes
wrapper.vm.$nextTick(() => {
expect(wrapper.classes()).not.toContain("hidden");
});
The only explanation I can find is
nextTick is used cuz the dom update is happing async
Could anyone give me a better explanation?
Does it mean the book material is deprecated?