jest
jest copied to clipboard
SocketIOClient implementation test fails with Async callback not invoked
🐛 Bug Report
To Reproduce
import SocketIO from 'socket.io-client'
import { chatHandler } from '../source'
let socket: SocketIOClient.Socket
afterAll((done) => {
chatHandler.close()
done()
})
beforeEach((done) => {
socket = SocketIO.connect('https://localhost:8087')
socket.on('connect', () => {
done()
})
})
afterEach((done) => {
if (socket.connected) {
socket.disconnect()
}
done()
})
describe('Chat implementation tests', () => {
test('EVENT - requestDisconnect', (done) => {
socket.emit('requestDisconnect')
socket.once('disconnect', () => {
expect(socket.connected).toBe(false)
done()
})
})
})
Where the chatHandler is the SocketIOServer and the requestDisconnect event disconnects the client.
Expected behavior
Test to pass, as socket.connected should be false
Current behavior

FAIL tests/Implementation.spec.ts (12.19s)
● Console
console.log source/communication/http/HTTPManager.ts:21
[SOCKET] Server started on port 8087
● Chat implementation tests › EVENT - requestDisconnect
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
at mapper (node_modules/jest-jasmine2/build/queueRunner.js:27:45)
● Chat implementation tests › EVENT - requestDisconnect
: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error:
24 |
25 | describe('Chat implementation tests', () => {
> 26 | test('EVENT - requestDisconnect', (done) => {
| ^
27 | socket.emit('requestDisconnect')
28 | socket.once('disconnect', () => {
29 | expect(socket.connected).toBe(false)
at new Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
at Suite.<anonymous> (tests/Implementation.spec.ts:26:2)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time: 12.994s
Ran all test suites.
A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --runInBand --detectOpenHandles to find leaks.```
## envinfo
System: OS: macOS Mojave 10.14.4 CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz Binaries: Node: 12.1.0 - /usr/local/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.14.2 - /usr/local/bin/npm npmPackages: jest: ^25.2.3 => 25.2.3
This still keeps happening, even with 30 second timeout. Sometimes the socket connects successfully and sometimes it just fails and times out.
Im having a similar issue, although in my case I am connecting to a redis-server, spun up using child_process.spawn. Also happens randomly (usually in CI as opposed to locally) and increasing timeout has no effect.
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
Still not resolved
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.