You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to mock the mixins used in the Vue component by passing in a fake mixin under global.mixins. But it seems to be not working on the Component while on the child component I can see the mocked method.
No difference on switching from shallowMount to mount.
import { shallowMount } from '@vue/test-utils';
import CommonChart from './common-chart';
const mockMixin = {
created() {
console.log('mock mixin created');
},
methods: {
downloadAsImage() {
console.log('mock mixin downloadAsImage');
}
}
};
let wrapper;
describe('Common chart', () => {
it.only('testing mixins', async () => {
wrapper = shallowMount(CommonChart, {
props: {},
global: {
plugins: [],
mocks: {},
mixins: [mockMixin]
}
});
await wrapper.vm.$nextTick();
let widgetExportAsImageWrapper = wrapper.findComponent('widget-export-as-image-stub');
console.log('Rendered HTML - \n', wrapper.html());
wrapper.vm.downloadAsImage(); // Points to the original import
widgetExportAsImageWrapper.vm.downloadAsImage(); // Points to the mocked mixin
});
});
Test output
mock mixin created
mock mixin created
Original mixins created
mock mixin created
Rendered HTML -
<div class="fill-height">
<widget-export-as-image-stub></widget-export-as-image-stub>
</div>
Original mixins downloadAsImage
mock mixin downloadAsImage
Expected behavior
wrapper.vm.downloadAsImage() should call to the mocked mixins method when invoked.
Do note that the tests are passing but the last two consoles are not as expected.
From
wrapper.vm.downloadAsImage(); // Points to the original import - Should be pointing to the mocked mixin???
widgetExportAsImageWrapper.vm.downloadAsImage(); // Points to the mocked mixin
Describe the bug
I am trying to mock the mixins used in the Vue component by passing in a fake mixin under
global.mixins
. But it seems to be not working on the Component while on the child component I can see the mocked method.No difference on switching from
shallowMount
tomount
.To Reproduce
common-chart.vue
chart-mixin.vue
test.spec.js
Test output
Expected behavior
wrapper.vm.downloadAsImage()
should call to the mocked mixins method when invoked.Related information:
The text was updated successfully, but these errors were encountered: