jest-websocket-mock
jest-websocket-mock copied to clipboard
Jest matcher feature request: something similar to .toMatchObject
It would be nice to be able to do .toReceiveMessage with behaviour similar to .toMatchObject .
My use case: I know what I expect the client to send, but each request contains an unknown/random id too.
Hi @kheyse-oqton !
That's a good idea :slightly_smiling_face:
Is that something you'd be willing to send a PR for?
It could be a new .toReceiveMessageMatching matcher, that behaves like .toMatchObject when jsonProtocol is true, and does a substring or regex match otherwise.
In the case of big/complex messages, the ability to use snapshots would be nice as well, either by chaining calls, or by providing toReceiveMessageMatchingSnapshot / toReceiveMessageMatchingInlineSnapshot.
Hi @antoinetissier !
You can already do this with
expect(await ws.nextMessage).toMatchSnapshot()
I don’t think it would be particularly useful to provide a wrapper around that.