I write test for my controller in Nestjs. I expect an array of employees contains object {id:1, firstname: 'john', lastname:'Dole'}
. So I write:
it('should get an employee', () => {
return controller.findAll('john').then((data) => {
expect(data).arrayContaining([
{
id: 1,
firstname: 'john',
lastname: 'Dole',
},
]);
});
});
but got error roperty 'arrayContaining' does not exist on type 'JestMatchers<Employee[]>'
Shall I install additional package or update jest in Nestjs? I've install "@nestjs/testing": "^7.6.15",
arrayContaining
doesn't do any matching by itself, instead it returns a matcher that can be used together with e.g. toEqual
, like so:
expect(data).toEqual(expect.arrayContaining([
{
id: 1,
firstname: 'john',
lastname: 'Dole',
},
]));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With