Add test for typecheckedOn

This commit is contained in:
Calvin Montgomery 2018-06-18 23:14:44 -07:00
parent 86e023d233
commit 4cad31d82c
1 changed files with 26 additions and 1 deletions

View File

@ -24,7 +24,6 @@ describe('UWSServer', () => {
if (type === 0) { if (type === 0) {
socket.test.emit(frame, payload); socket.test.emit(frame, payload);
} else if (type === 1) { } else if (type === 1) {
console.log(message.data);
socket.test.emit('ack', ackId, payload); 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();
});
};
});
}); });