在我的AudioPlyar组件中,定义了一个计算的onAir()布局
computed: {
onAir() {
return this.autoplay && !this.playing && this.seek === 0 ? false : true;
}
},
在上面定义了一个观察者:
watch: {
onAir() {
if (this.onAir === false) {
this.stop();
this.$emit("playerStop");
}
}
},
我正在尝试测试此观察器,但是它正在生病...
it("watcher onAir", () => {
// given
const wrapper = shallowMount(AudioPlayer, {
propsData: {
sources: ['require("@/assets/audio/ultimo_desejo.mp3"'],
autoplay: true,
loop: false,
percentage: 0,
playing: true,
onAir: true
},
mixins: [VueHowler]
});
const spy = jest.fn();
wrapper.vm.$on("playerStop", spy);
// when
wrapper.setData({ onAir: false });
// then
expect(wrapper.vm.onAir).toBe(false); // OK
expect(spy).toHaveBeenCalledTimes(1); // NOT CALLED ...
});
欢迎任何反馈...