Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { mount, RouterLinkStub } from "@vue/test-utils";
import Err from "@/views/Err.vue";
import Search from "@/api/search.js";
import { expect } from "../../../node_modules/vitest/dist/index";
vi.mock("../../../src/api/search.js");
describe("Err.vue", () => {
afterEach(() => {
vi.clearAllMocks();
});
it("should attempt multiple searches with increasing fuzzyness", async () => {
const mockSearch = vi.fn().mockReturnValue([]);
Search.mockImplementation(() => ({
search: mockSearch,
}));
const wrapper = mount(Err, {
stubs: {
RouterLink: RouterLinkStub,
},
mocks: {
$route: {
fullPath: "/mock/path",
},
},
});
expect(mockSearch).toHaveBeenCalledTimes(4);
expect(mockSearch.mock.calls[0][0]).toEqual("mock~0 path~0");
expect(mockSearch.mock.calls[1][0]).toEqual("mock~1 path~1");
expect(mockSearch.mock.calls[2][0]).toEqual("mock~2 path~2");
expect(mockSearch.mock.calls[3][0]).toEqual("mock~3 path~3");
});
it("should add suggestions and exit early", async () => {
const mockSearch = vi
.fn()
.mockReturnValueOnce([{ ref: "/" }, { ref: "/services" }])
.mockReturnValueOnce([{ ref: "/products/cnap" }]);
Search.mockImplementation(() => ({
search: mockSearch,
}));
const wrapper = mount(Err, {
stubs: {
RouterLink: RouterLinkStub,
},
mocks: {
$route: {
fullPath: "/mock/path",
},
},
});
expect(mockSearch).toHaveBeenCalledTimes(2);
expect(mockSearch.mock.calls[0][0]).toEqual("mock~0 path~0");
expect(mockSearch.mock.calls[1][0]).toEqual("mock~1 path~1");
expect(wrapper.vm.pageSuggestions.length).toEqual(3);
});
});