I have an alert component which has a flag isVisible, this flag is becoming true when the component is created, and also in the created HOOK I have a setTimeout which starts if the component receives DESTROY boolean prop:
props: {
destroy: {
type: Boolean,
default: false,
},
}
data() {
return {
isVisible: false,
}
}
created() {
this.isVisible = true
if (this.destroy) {
setTimeout(() => {
this.isVisible = false
}, 2500)
},
}
I am using VUE UTILS / JEST to test if the component disappears after setTimeout is over, I've tried:
test('Component dissapears after 2.5 seconds when it receives DESTROY prop', async () => {
const component = wrapper.get('[data-test-id="info-alert-wrapper"]')
await wrapper.setProps({
destroy: true,
})
await wrapper.vm.$options.created.call()
expect(component.isVisible()).toBeFalsy()
})
But it responds: TypeError: Cannot set property 'isVisible' of undefined
Can somebody help me with this? thank u! :)