jest-websocket-mock icon indicating copy to clipboard operation
jest-websocket-mock copied to clipboard

Jest matcher feature request: something similar to .toMatchObject

Open kheyse-werk opened this issue 6 years ago • 3 comments

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.

kheyse-werk avatar Jun 28 '19 10:06 kheyse-werk

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.

romgain avatar Jul 08 '19 06:07 romgain

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.

antoinetissier avatar Feb 25 '21 10:02 antoinetissier

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.

romgain avatar Feb 25 '21 10:02 romgain