I'm trying to test my SiWizard component that uses external dependencies. It imports modules from the syncfusion library.
SiWizard.vue imports
import SiFooter from "@/components/subComponents/SiFooter.vue";
import { Prop, Component, Vue } from "vue-property-decorator";
import { TabPlugin, TabComponent, SelectingEventArgs } from "@syncfusion/ej2-vue-navigations";
import { VNode } from "vue";
Vue.use(TabPlugin);
And this is what my test looks like, using vue js test utils and jest. Just to keep things simple my test case should pass and configured a single prop.
siWizard.spec.ts
import { shallowMount, Wrapper } from "@vue/test-utils";
import SiWizard from "../../src/components/SiWizard.vue";
let wrapper: Wrapper<SiWizard & { [key: string]: any }>;
describe("testing SiWizard", () => {
test("Test add mode", () => {
wrapper = shallowMount(SiWizard, {
propsData: {
mode: "add"
}
});
expect(true).toBe(true)
});
When running the siWizard.spec.ts I get weird errors. Error without mocking, test still passes
My guess is that properties in the test environment can't access the dependency properties used in the SiWizard component. Therefor I have to mock the TabPlugin using Jest. So I tried to mock the dependency using jest.mock.
import { shallowMount, Wrapper } from "@vue/test-utils";
import SiWizard from "../../src/components/SiWizard.vue";
// import { TabPlugin } from "@syncfusion/ej2-vue-navigations";
jest.mock("../../node_modules/@syncfusion/ej2-navigations" , () => { jest.fn() });
let wrapper: Wrapper<SiWizard & { [key: string]: any }>;
describe("testing SiWizard", () => {
test("Test add mode", () => {
wrapper = shallowMount(SiWizard, {
propsData: {
mode: "add"
}
});
expect(true).toBe(true)
});
Resulting in a test that fails and giving the following error Error and failing test
I'm not sure if I need to mock anything because my first test still passes but it only gives me errors. Can anyone tell me if I mock correctly or do I need to do something else?