Vue.js vue-test-utils Как проверить наблюдателя? - PullRequest
0 голосов
/ 30 сентября 2018

В моем компоненте 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 ...
});

Любые отзывы приветствуются ...

...