在我的 AudioPlyar 组件中,定义了一个计算的 onAir() popery
computed: {
onAir() {
return this.autoplay && !this.playing && this.seek === 0 ? false : true;
}
},
Run Code Online (Sandbox Code Playgroud)
并在其上定义了一个观察者:
watch: {
onAir() {
if (this.onAir === false) {
this.stop();
this.$emit("playerStop");
}
}
},
Run Code Online (Sandbox Code Playgroud)
我正在尝试测试这个观察者,但它有问题......
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 ...
});
Run Code Online (Sandbox Code Playgroud)
欢迎任何反馈...
| 归档时间: |
|
| 查看次数: |
4747 次 |
| 最近记录: |