Skip to content

Struggle to properly mock child component with third party dependency in it #2215

Closed Answered by cexbrayat
yevhendevbox asked this question in Q&A
Discussion options

You must be logged in to vote

If you use shallow mount, then the child component is not used, but the import to your third party lib is still executed, and fails with TypeError: window.matchMedia is not a function, because jsdom probably does not support this function.

So you can either patch the window object to add matchMedia in your test (maybe look on the issue tracker of jsdom), or mock the third dependency completely if you use shallowMount:

vi.mock('@kolirt/vue-web3-auth', () => {
  return {};
});

describe('LoginView.vue', () => {
  const wrapper = shallowMount(LoginView);
  it('should render properly', () => {
    expect(wrapper.exists()).toBeTruthy();
  });
});

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yevhendevbox
Comment options

Answer selected by yevhendevbox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants