When using provide/inject, we are currently mocking @tuleap/strict-inject
in every test. @vue/test-utils
can help us: by leveraging its configuration, we can inject just like in production, which makes mocking unnecessary.
// Stop doing this:
vi.mock("@tuleap/vue-strict-inject");
vi.spyOn(strict_inject, "strictInject").mockImplementation((key) => {
switch (key) {
case MY_INJECTION:
return 123;
case MY_OTHER_INJECTION:
return "abc";
}
});
// Do this instead:
function getWrapper(): VueWrapper {
return shallowMount(MyComponent, {
global: {
provide: {
[MY_INJECTION.valueOf()]: 123,
[MY_OTHER_INJECTION.valueOf()]: "abc",
},
},
});
}