jest-websocket-mock
jest-websocket-mock copied to clipboard
Open handles
When using the library, I run the tests and the suite completes fine. However, I get a warning from a jest that there might be open handles.
When I run npm test -- --detectOpenHandles jest always complains about using the toReceiveMessage matcher.
Example:
● Timeout
146 |
147 | const promisedResponse = client.createWithdrawTicket(params);
> 148 | await expect(server).toReceiveMessage(JSON.stringify({ m: 0, i: 0, n: 'CreateWithdrawTicket', o: JSON.stringify({
| ^
149 | TfaType: 'Google',
150 | TfaCode: TfaCode,
151 | Payload: JSON.stringify({
at ../node_modules/jest-websocket-mock/lib/jest-websocket-mock.cjs.js:206:89
at Object.toReceiveMessage (../node_modules/jest-websocket-mock/lib/jest-websocket-mock.cjs.js:206:66)
at __EXTERNAL_MATCHER_TRAP__ (../node_modules/expect/build/index.js:386:30)
at Object.throwingMatcher [as toReceiveMessage] (../node_modules/expect/build/index.js:387:15)
at lib/apex/apexClient.spec.ts:148:28
at lib/apex/apexClient.spec.ts:8:71
at Object.<anonymous>.__awaiter (lib/apex/apexClient.spec.ts:4:12)
at Object.<anonymous> (lib/apex/apexClient.spec.ts:131:74)
at TestScheduler.scheduleTests (../node_modules/@jest/core/build/TestScheduler.js:333:13)
at runJest (../node_modules/@jest/core/build/runJest.js:387:19)
at _run10000 (../node_modules/@jest/core/build/cli/index.js:408:7)
at runCLI (../node_modules/@jest/core/build/cli/index.js:261:3)
This is because the code internally does:
Promise.race([yourPromise, setTimeout(...)])
Is there a way to configure it to tear down the timeouts it sets?
Hi @matiasgarcia ! Thanks for reporting this!
Good catch, it looks we're not cleaning up that timeout... Would you be open to sending a PR for this? I think the offending code is around here: https://github.com/romgain/jest-websocket-mock/blob/master/src/matchers.ts#L51
Thanks!