jwt decode mock function

Skip to first unread message

Lukas Wilkeer

May 12, 2020, 1:04:02 PM5/12/20
to nodejs
Hi folks.

I have a socket.io server that verify the extra headers for authorization tokens, in that case, I use the jwt to validate de token and validate the connection.

Therefore, um a unit test case, I need to mock the decode function to test the connection. Where is a simple unit test case that check the connection event, I don't necessary need to send the token, as I can mock the decode behaviour to return true to my handshake validator and connects successfully.

My problem where: the authStub, that is a jwt.decode stub, doesn't get called, so my test fails.

Here is a gist with connection test(index.test.js) and my authenticate method, the where called by a middleware(socket.use) with the headers and socket as parameters,

What could be wrong? In the first assertion, the authStub should get called, but there's not.
Reply all
Reply to author
0 new messages