Vue test utils,测试是否调用了typescript组件上的函数
我有一个具有异步登录方法的Vue(ts类)组件。 我有一个vuetify按钮在里面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
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可以解决测试问题。但我应该拥有它吗?