【发布时间】:2019-11-27 17:52:57
【问题描述】:
我的 Vue 组件有以下单元测试:
import { shallowMount } from '@vue/test-utils';
import OrganizationChildren from './OrganizationChildren.vue';
describe('OrganizationChildren', () => {
beforeEach(() => {
jest.resetModules();
});
it('passes', () => {
jest.doMock('@/adonis-api', () => {
return {
organization: {
family(id) {
return {
descendants: [],
};
},
},
};
});
const wrapper = shallowMount(OrganizationChildren, {
propsData: {
org: {
id: 1,
},
},
});
});
});
而在 Vue 组件中,它是 import { organization } from '@/adonis-api';。我暂时只是 console.logging 导入的organization 对象,以确保它是正确的。但我可以看到它没有使用我指定的模拟版本。我究竟做错了什么?我的目标是在每个 it() 块中以不同方式模拟 family 方法,以测试如果 descendants 为空、包含 5 个项目、100 个项目等会发生什么。
【问题讨论】:
标签: javascript vue.js jestjs vue-test-utils