-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathvercelWaitUntil.test.ts
40 lines (36 loc) · 1.41 KB
/
vercelWaitUntil.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
38
39
40
import { describe, expect, it, vi } from 'vitest';
import { vercelWaitUntil } from '../../src/utils-hoist/vercelWaitUntil';
import { GLOBAL_OBJ } from '../../src/utils-hoist/worldwide';
describe('vercelWaitUntil', () => {
it('should do nothing if GLOBAL_OBJ does not have the @vercel/request-context symbol', () => {
const task = Promise.resolve();
vercelWaitUntil(task);
// No assertions needed, just ensuring no errors are thrown
});
it('should do nothing if get method is not defined', () => {
// @ts-expect-error - Not typed
GLOBAL_OBJ[Symbol.for('@vercel/request-context')] = {};
const task = Promise.resolve();
vercelWaitUntil(task);
// No assertions needed, just ensuring no errors are thrown
});
it('should do nothing if waitUntil method is not defined', () => {
// @ts-expect-error - Not typed
GLOBAL_OBJ[Symbol.for('@vercel/request-context')] = {
get: () => ({}),
};
const task = Promise.resolve();
vercelWaitUntil(task);
// No assertions needed, just ensuring no errors are thrown
});
it('should call waitUntil method if it is defined', () => {
const waitUntilMock = vi.fn();
// @ts-expect-error - Not typed
GLOBAL_OBJ[Symbol.for('@vercel/request-context')] = {
get: () => ({ waitUntil: waitUntilMock }),
};
const task = Promise.resolve();
vercelWaitUntil(task);
expect(waitUntilMock).toHaveBeenCalledWith(task);
});
});