From 4cad31d82ca2a2c95d40bba1e19fc189cb6b1855 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Mon, 18 Jun 2018 23:14:44 -0700 Subject: [PATCH] Add test for typecheckedOn --- test/io/uws.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/io/uws.js b/test/io/uws.js index 91c1d20c..d72d7410 100644 --- a/test/io/uws.js +++ b/test/io/uws.js @@ -24,7 +24,6 @@ describe('UWSServer', () => { if (type === 0) { socket.test.emit(frame, payload); } else if (type === 1) { - console.log(message.data); socket.test.emit('ack', ackId, payload); } }; @@ -140,4 +139,30 @@ describe('UWSServer', () => { }); }; }); + + it('typechecks input frames', done => { + server.on('connection', s => { + s.typecheckedOn('test', { foo: 'string' }, data => { + assert.fail('Should not have reached callback'); + }); + }); + + socket = connect(); + socket.onopen = () => { + socket.send(JSON.stringify({ + type: 0, + frame: 'test', + payload: { foo: 123 } + })); + + socket.test.on('errorMsg', payload => { + assert.equal( + payload.msg, + 'Unexpected error for message test: ' + + 'Expected key foo to be of type string, instead got number' + ); + done(); + }); + }; + }); });