Skip to content

Commit 82dcb93

Browse files
authored
edit tests
1 parent 366264f commit 82dcb93

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

packages/node/test/handlers.test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,24 +284,35 @@ describe('requestHandler', () => {
284284
});
285285
});
286286

287+
it('patches `res.end`', () => {
288+
const flush = jest.spyOn(SDK, 'flush').mockResolvedValue(true);
289+
290+
sentryRequestMiddleware(req, res, next);
291+
res.end('ok');
292+
293+
setImmediate(() => {
294+
expect(flush).toHaveBeenCalled();
295+
expect(res.finished).toBe(true);
296+
});
297+
});
298+
287299
it('patches `res.end` when `flushTimeout` is specified', () => {
288300
const flush = jest.spyOn(SDK, 'flush').mockResolvedValue(true);
289301

290-
const handler = requestHandler({ flushTimeout: 1337 });
291-
handler(req, res, next);
302+
const sentryRequestMiddleware = requestHandler({ flushTimeout: 1337 });
303+
sentryRequestMiddleware(req, res, next);
292304
res.end('ok');
293305

294306
setImmediate(() => {
295-
expect(flush).toBeCalledWith(1337);
307+
expect(flush).toHaveBeenCalledWith(1337);
296308
expect(res.finished).toBe(true);
297309
});
298310
});
299311

300312
it('prevents errors thrown during `flush` from breaking the response', async () => {
301313
jest.spyOn(SDK, 'flush').mockRejectedValue(new SentryError('HTTP Error (429)'));
302314

303-
const handler = requestHandler({ flushTimeout: 1337 });
304-
handler(req, res, next);
315+
sentryRequestMiddleware(req, res, next);
305316
res.end('ok');
306317

307318
setImmediate(() => {

0 commit comments

Comments
 (0)