debianize-mobilizon/tests/unit/specs/components/navbar.spec.ts
Thomas Citharel 2e72f6faf4
build: switch from yarn to npm to manage js dependencies and move js contents to root
yarn v1 is being deprecated and starts to have some issues

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2023-11-14 17:24:42 +01:00

60 lines
1.5 KiB
TypeScript

const useRouterMock = vi.fn(() => ({
push: function () {
// do nothing
},
}));
import { shallowMount, VueWrapper } from "@vue/test-utils";
import NavBar from "@/components/NavBar.vue";
import { createMockClient, MockApolloClient } from "mock-apollo-client";
import buildCurrentUserResolver from "@/apollo/user";
import { InMemoryCache } from "@apollo/client/cache";
import { describe, it, vi, expect, afterEach } from "vitest";
import { DefaultApolloClient } from "@vue/apollo-composable";
vi.mock("vue-router/dist/vue-router.mjs", () => ({
useRouter: useRouterMock,
}));
describe("App component", () => {
let wrapper: VueWrapper;
let mockClient: MockApolloClient | null;
const createComponent = () => {
const cache = new InMemoryCache({ addTypename: false });
mockClient = createMockClient({
cache,
resolvers: buildCurrentUserResolver(cache),
});
wrapper = shallowMount(NavBar, {
// stubs: ["router-link", "router-view", "o-dropdown", "o-dropdown-item"],
global: {
provide: {
[DefaultApolloClient]: mockClient,
},
},
});
};
afterEach(() => {
wrapper?.unmount();
mockClient = null;
});
it("renders a Vue component", async () => {
const push = vi.fn();
useRouterMock.mockImplementationOnce(() => ({
push,
}));
createComponent();
await wrapper.vm.$nextTick();
expect(wrapper.exists()).toBe(true);
expect(wrapper.html()).toMatchSnapshot();
// expect(wrapper.findComponent({ name: "b-navbar" }).exists()).toBeTruthy();
});
});