jest-websocket-mock
jest-websocket-mock copied to clipboard
Add new "toReceiveMessage" matcher that checks all sent messages instead of next message
Fixes #51
Finally got around to this. This is what I'm thinking of for the new toReceiveMessage matcher, as we discussed before.
Here are some example failure messages:
Wrong message received
expect(WS).toReceiveMessage(expected)
Expected the following message within 1000ms:
"PRIVMSG #mychannel :Not the message"
but instead received the following messages:
["PASS mypass", "NICK coteh", "USER coteh 0 * :James", "PRIVMSG #mychannel :Hello there"]
Difference:
- Expected
+ Received
Array [
- "PRIVMSG #mychannel :Not the message",
+ "PASS mypass",
+ "NICK coteh",
+ "USER coteh 0 * :James",
+ "PRIVMSG #mychannel :Hello there",
]
Message never received
expect(WS).toReceiveMessage(expected)
Expected the following message within 1000ms:
"PRIVMSG #mychannel :Hello there"
but instead received the following messages:
["PASS mypass", "NICK coteh", "USER coteh 0 * :James"]
Difference:
- Expected
+ Received
Array [
- "PRIVMSG #mychannel :Hello there",
+ "PASS mypass",
+ "NICK coteh",
+ "USER coteh 0 * :James",
]
Nothing was received at all
expect(WS).toReceiveMessage(expected)
Expected the following message within 1000ms:
"PRIVMSG #mychannel :Hello there"
but it didn't receive anything.
Let me know your thoughts. If you think it looks good and can still benefit the project, I'll take this out of draft, polish it up a bit, and apply any feedback you may have. Thanks!