Assuming I have a class like this:
class Cat {
constructor(name) {
this.name = name;
}
}
and a failing test like this:
expect(new Cat('Bob')).toEqual(new Cat('Alice'));
Instead of:
- Expected - 1
+ Received + 1
Cat {
- "name": "Alice",
+ "name": "Bob",
}
I would like to see e.g. (doesn't have to be exactly like this, just in some way customizable):
Expected: "Cat named Alice"
Received: "Cat named Bob"
I tried defining a toString() method and get [Symbol.toStringTag](). The former did nothing, the latter helped with console.log but not with Jest's diff. Is there any way to achieve this?