Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue test utils,测试是否调用了typescript组件上的函数_Typescript_Unit Testing_Vue.js_Vuejs2_Vue Test Utils - Fatal编程技术网

Vue test utils,测试是否调用了typescript组件上的函数

Vue test utils,测试是否调用了typescript组件上的函数,typescript,unit-testing,vue.js,vuejs2,vue-test-utils,Typescript,Unit Testing,Vue.js,Vuejs2,Vue Test Utils,我有一个具有异步登录方法的Vue(ts类)组件。 我有一个vuetify按钮在里面 const wrapper = shallowMount(LoginComponent, { localVue, vuetify, computed: { isLoggedIn() { return false; } }, }); const loginBtn = wrapper.find('[data-cy=\'login-button\']'); expect(l

我有一个具有异步登录方法的Vue(ts类)组件。 我有一个vuetify按钮在里面

const wrapper = shallowMount(LoginComponent, {
  localVue,
  vuetify,
  computed: {
    isLoggedIn() {
      return false;
    }
  },
});

const loginBtn = wrapper.find('[data-cy=\'login-button\']');
expect(loginBtn.exists()).toBe(true);
expect(loginBtn.element).toBeVisible();
当我尝试添加一个mock并触发它的调用时,它不起作用。它只是说预期的呼叫数为1,收到的呼叫数为0。 问题是什么

const login = jest.spyOn(wrapper.vm, 'login');
loginBtn.trigger('click');
await wrapper.vm.$nextTick();
expect(login).toHaveBeenCalled();

实际上,将.native添加到@click可以解决测试问题。但我应该拥有它吗?