但是如果我一起运行它们,包装器似乎有问题
这是我的两个“ beforeEach”的样子
TypeError:无法读取未定义的属性“ props”
describe('Modal.vue', () => {
let store: any;
let wrapper: any;
beforeEach(() => {
const localVue = createLocalVue();
localVue.use(Vuex);
store = new Vuex.Store(cloneDeep(StoreConfig));
wrapper = shallowMount(Modal, {
localVue,
store,
});
});
// Tests...
});
describe('Navigation.vue', () => {
let store: any;
let wrapper: any;
beforeEach(() => {
const router = new VueRouter();
const localVue = createLocalVue();
localVue.use(VueRouter);
localVue.use(Vuex);
store = new Vuex.Store(cloneDeep(StoreConfig));
wrapper = shallowMount(Navigation, {
localVue,
router,
store,
propsData: {
user: {},
},
});
});
it('show a login button when user is a guest', () => {
setUserAsGuest();
expect(wrapper.html()).toContain('Login');
});
const setUserAsGuest = () => {
wrapper.setProps({
user: {
role: 'guest',
},
});
// More Tests...
});
我已经尽力想想了,所以现在我要把自己转向你们!