Skip to content

Commit

Permalink
fix: add null check for connection.headers
Browse files Browse the repository at this point in the history
  • Loading branch information
wood1986 committed Aug 17, 2019
1 parent 2d44ef8 commit 96bf165
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/servers/SockJSServer.js
Expand Up @@ -64,7 +64,7 @@ module.exports = class SockJSServer extends BaseServer {
// f should be passed the resulting connection and the connection headers
onConnection(f) {
this.socket.on('connection', (connection) => {
f(connection, connection.headers);
f(connection, connection ? connection.headers : null);
});
}

Expand Down
15 changes: 13 additions & 2 deletions test/server/servers/SockJSServer.test.js
Expand Up @@ -10,7 +10,7 @@ describe('SockJSServer', () => {
let socketServer;
let listeningApp;

beforeAll((done) => {
beforeEach((done) => {
// eslint-disable-next-line new-cap
const app = new express();

Expand Down Expand Up @@ -84,9 +84,20 @@ describe('SockJSServer', () => {
done();
}, 3000);
});

it('should not throw an exception when connection is null', (done) => {
expect(() => {
socketServer.onConnection(() => {});
socketServer.socket.emit('connection', null);
}).not.toThrow();

setTimeout(() => {
done();
}, 1000);
});
});

afterAll((done) => {
afterEach((done) => {
listeningApp.close(done);
});
});

0 comments on commit 96bf165

Please sign in to comment.