This is a follow-up question to this question:
I don't only want to test if the function throws an error but also if the thrown error has the same Error Message. So i tried:
expect(Person.getPerson.bind(Person, id)).to.throw(new Error(`Person ${id} not found`));
inside the getPerson function an Error is thrown lilke this:
if (!isPersonExistent(id)) {
throw new Error(`Person ${id} not found`);
}
and the given message looks like this:
AssertionError: expected [Function: bound getPerson] to throw 'Error: Person 1 not found' but 'Error: Person 1 not found' was thrown
I guess it has something to do with the two error objects being two different objects. But how do I also test if they have the same error message. Optimally all in one step.
Aucun commentaire:
Enregistrer un commentaire