In order to test a beforeDestroy() hook in my component, I wrote the following spec :
it("should test lifecycle when audio tag is destroyed", () => {
// jsdom doesn't support any loading or playback media operations.
// As a workaround you can add a few stubs in your test setup:
window.HTMLMediaElement.prototype.removeEventListener = () => { /* do nothing */ };
// given
const wrapper = mount(AudioPlayer, {
// attachToDocument: true,
propsData: {
autoPlay: false,
file: file,
ended,
canPlay
}
});
wrapper.vm.loaded = true; // enable buttons
const player = wrapper.find("#player");
expect(wrapper.contains('#playPauseBtn')).toBe(true);
// when
player.destroy()
// then
expect(wrapper.contains('#playPauseBtn')).toBe(false);
});
but I am getting an error, even if the destroy() is used as in the doc ...
[vue-test-utils]: wrapper.destroy() can only be called on a Vue instance
177 | expect(wrapper.contains('#playPauseBtn')).toBe(true); // OK
178 | // when
> 179 | player.destroy()
where am I wrong ?
thanks for feedback
wrapper(wrapper.destroy() can only be...), but your code (and the marker) leads toplayer(player.destroy()) - which one is right?