Skip to content

Tag: jestjs

Jest failing async test

I am getting the current error I think the issue comes down to this line of code If I change that code to this I no longer get the error. I need this function to return null so I can test the failing code. Here is the method I am testing I have seen a few posts online stating that

Jest expect to array contains element

Let’s suppose that I have the following code: And I want to check if id is in arrayOfIds Something like this How can I do this with Jest? Answer Use .toContain when you want to check that an item is in an array. For testing the items in the array, this uses ===, a strict equality check.

How to test method called in promise

I have a function that saves an entity and in the promise i want to check the delete is called. In my jest test it whizzes past and can’t think how to test it Here is the partial snippets, it all works, Promises called etc. just can’t figure how to test that ‘deleteMessage’ is called I…