-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathraise.test.ts
37 lines (31 loc) · 1.16 KB
/
raise.test.ts
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
import { describe, beforeEach, afterEach, it, expect, vitest } from "vitest";
import { raise } from "../src/utils/raise";
describe(raise.name, () => {
beforeEach(() => {
vitest.spyOn(console, "error").mockImplementation(() => {}); // Mock console.error
});
afterEach(() => {
vitest.restoreAllMocks(); // Restore console.error to its original state
});
it("should log the issue to the console and return null", () => {
const issue = "An error occurred";
const result = raise(issue);
expect(console.error).toHaveBeenCalledWith(issue);
expect(result).toBeNull();
});
it("should include the snippet in the log message if provided", () => {
const issue = "An error occurred";
const snippet = "mySnippet";
const result = raise(issue, snippet);
expect(console.error).toHaveBeenCalledWith(
`An error occurred in 'mySnippet'`
);
expect(result).toBeNull();
});
it('should not include "in" if the snippet is not provided', () => {
const issue = "An error occurred";
const result = raise(issue, "");
expect(console.error).toHaveBeenCalledWith("An error occurred");
expect(result).toBeNull();
});
});