|
| 1 | +import { vercelWaitUntil } from '../src/vercelWaitUntil'; |
| 2 | +import { GLOBAL_OBJ } from '../src/worldwide'; |
| 3 | + |
| 4 | +describe('vercelWaitUntil', () => { |
| 5 | + it('should do nothing if GLOBAL_OBJ does not have the @vercel/request-context symbol', () => { |
| 6 | + const task = Promise.resolve(); |
| 7 | + vercelWaitUntil(task); |
| 8 | + // No assertions needed, just ensuring no errors are thrown |
| 9 | + }); |
| 10 | + |
| 11 | + it('should do nothing if get method is not defined', () => { |
| 12 | + // @ts-expect-error - Not typed |
| 13 | + GLOBAL_OBJ[Symbol.for('@vercel/request-context')] = {}; |
| 14 | + const task = Promise.resolve(); |
| 15 | + vercelWaitUntil(task); |
| 16 | + // No assertions needed, just ensuring no errors are thrown |
| 17 | + }); |
| 18 | + |
| 19 | + it('should do nothing if waitUntil method is not defined', () => { |
| 20 | + // @ts-expect-error - Not typed |
| 21 | + GLOBAL_OBJ[Symbol.for('@vercel/request-context')] = { |
| 22 | + get: () => ({}), |
| 23 | + }; |
| 24 | + const task = Promise.resolve(); |
| 25 | + vercelWaitUntil(task); |
| 26 | + // No assertions needed, just ensuring no errors are thrown |
| 27 | + }); |
| 28 | + |
| 29 | + it('should call waitUntil method if it is defined', () => { |
| 30 | + const waitUntilMock = jest.fn(); |
| 31 | + // @ts-expect-error - Not typed |
| 32 | + GLOBAL_OBJ[Symbol.for('@vercel/request-context')] = { |
| 33 | + get: () => ({ waitUntil: waitUntilMock }), |
| 34 | + }; |
| 35 | + const task = Promise.resolve(); |
| 36 | + vercelWaitUntil(task); |
| 37 | + expect(waitUntilMock).toHaveBeenCalledWith(task); |
| 38 | + }); |
| 39 | +}); |
0 commit comments