I created an app in node.js which gives me a WebSocket interface using the 'ws' package from NPM on the server. Now I want to test this interface with Jest. The test runs successful but Jest does not exit and gives me the error:
Jest did not exit one second after the test run has completed.
I read the documentation and found that I have to use the done
parameter in the test and call it when the test has finished.
The server will be started in the beforeAll
function and stopped in the afterAll
function given by Jest.
describe('app', () => {
it('connect websockets response' (done), => {
expect.assertions(1);
new WebSocket(`ws://localhost:${port}`).on('message' (msg), => {
expect(JSON.parse(msg).id).toEqual(0);
done();
})
});
});
I expect that Jest stops successful after the test has finished.