-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtimer.test.ts
More file actions
32 lines (26 loc) · 941 Bytes
/
Copy pathtimer.test.ts
File metadata and controls
32 lines (26 loc) · 941 Bytes
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
import { describe, expect, it, vi } from 'vitest';
import { safeUnref } from '../../../src/utils/timer';
describe('safeUnref', () => {
it('calls unref on a NodeJS timer', () => {
const timeout = setTimeout(() => {}, 1000);
const unrefSpy = vi.spyOn(timeout, 'unref');
safeUnref(timeout);
expect(unrefSpy).toHaveBeenCalledOnce();
});
it('returns the timer', () => {
const timeout = setTimeout(() => {}, 1000);
const result = safeUnref(timeout);
expect(result).toBe(timeout);
});
it('handles multiple unref calls', () => {
const timeout = setTimeout(() => {}, 1000);
const unrefSpy = vi.spyOn(timeout, 'unref');
const result = safeUnref(timeout);
result.unref();
expect(unrefSpy).toHaveBeenCalledTimes(2);
});
it("doesn't throw for a browser timer", () => {
const timer = safeUnref(385 as unknown as ReturnType<typeof setTimeout>);
expect(timer).toBe(385);
});
});