西装之间的vue-test-utils冲突

时间:2018-11-11 21:03:48

标签: javascript vue.js vuejs2 mocha vue-test-utils

我有两个测试服,如果我独立运行它们,则所有测试都通过: enter image description here

但是如果我一起运行它们,包装器似乎有问题

  

TypeError:无法读取未定义的属性“ props”:   enter image description here

这是我的两个“ 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...
});

我已经尽力想想了,所以现在我要把自己转向你们!

0 个答案:

没有答案