Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'arraycontaining' does not exist on type 'jestmatchers'

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",

like image 992
Tim Woohoo Avatar asked Oct 19 '25 03:10

Tim Woohoo


1 Answers

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',
        },
      ]));
like image 132
emlai Avatar answered Oct 22 '25 03:10

emlai