James
James

Reputation: 1065

Vue Unit Testing - Mocking a plugins return value

I have a custom plugin that returns a boolean. Rather than importing the plugin to the test, I want to mock this value. I can mock the plugin easily enough, but how can I change the return value in the test?

const $mq = () => {};    
wrapper = shallowMount(Component, { 
  //...
  mocks: {
    $mq
  }
  //...
});

Test

it ('Test description', () => {
  wrapper.vm.$mq = () => true; // HOW TO MOCK PLUGIN RETURNS???
});

Upvotes: 1

Views: 1113

Answers (1)

James
James

Reputation: 1065

Incase anyone comes along this, you need to change the value before providing it to the mocks option.

const $mq = () => true;    
wrapper = shallowMount(Component, { 
  //...
  mocks: {
    $mq
  }
  //...
});

Upvotes: 2

Related Questions