-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.test.js
More file actions
60 lines (46 loc) · 1.49 KB
/
app.test.js
File metadata and controls
60 lines (46 loc) · 1.49 KB
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
import showMenu from "./menu.mjs";
import generateArchitecture from "./architecture.mjs";
jest.mock("./menu.mjs", () => ({
__esModule: true,
default: jest.fn(),
}));
jest.mock("./architecture.mjs", () => ({
__esModule: true,
default: jest.fn(),
}));
describe("main function", () => {
let consoleLogSpy;
let consoleErrorSpy;
beforeEach(() => {
consoleLogSpy = jest.spyOn(console, "log");
consoleErrorSpy = jest.spyOn(console, "error");
});
afterEach(() => {
jest.clearAllMocks();
});
test("should call showMenu and generateArchitecture functions", async () => {
showMenu.mockResolvedValueOnce("mvc");
generateArchitecture.mockResolvedValueOnce();
await import("./app.mjs");
expect(showMenu).toHaveBeenCalled();
expect(generateArchitecture).toHaveBeenCalledWith("mvc");
});
test("should log success message when project generation is successful", async () => {
showMenu.mockResolvedValueOnce("mvc");
generateArchitecture.mockResolvedValueOnce();
await import("./app.mjs");
expect(consoleLogSpy).toHaveBeenCalledWith(
"Project successfully generated!"
);
});
test("should log error message when project generation fails", async () => {
showMenu.mockResolvedValueOnce("invalid");
generateArchitecture.mockRejectedValueOnce(
new Error("Invalid architecture selected")
);
await import("./app.mjs");
expect(consoleErrorSpy).toHaveBeenCalledWith(
"Invalid architecture selected"
);
});
});