Currently, I am in the process of testing my SiWizard component, which relies on external dependencies from the syncfusion library. The component imports various modules from this 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);
In order to simplify things, I have created a test case using vue js test utils and jest. The aim is for this test to pass by configuring 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)
});
During the execution of siWizard.spec.ts, I encountered some strange errors. Error without mocking, test still passes
My assumption is that the properties in the test environment are unable to access the dependency properties utilized in the SiWizard component. Therefore, I attempted to mock the TabPlugin using Jest. Subsequently, I tried mocking the dependency with 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)
});
The end result was a failing test with the following error message Error and failing test
Uncertain if the need for mocking is necessary since the initial test still passes but continues to display errors. Can someone advise me on whether my mocking approach is correct or if there is something else I should be doing?