Test error with array messages content containing message in jest test.each

1 · Adrian Matei · March 8, 2023, 11:35 a.m.
When validating a note, bookmark or snippet on Codever several validation rules might be broken and the response given to the consumer will contain all the corresponding error messages. In the following example we will consider the case of notes and how we can verify in jest repetitive tests if a broken rule is present in the error response. To do that we surround the method under test in a try catch block and use jest expect.arrayContaining assertion on the validationErrors array in the error c...