4

在我的 AudioPlyar 组件中,定义了一个计算的 onAir() popery

 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 ...
});

欢迎任何反馈...

4

0 回答 0