[JEST] Mongoose findOneAndUpdate untestable?

Hi,

Need an advice about unit test… I need to test a findOneAndUpdate Mongoose function. This function returns the object it updated but I can’t use this inside the expect().toBe(). Any advice?

my code :

test('Update and tell them !', async () => {

    let clientUpdated = await Client.findOneAndUpdate({ id: '2' }, { dbServer: 'myServer' }, { new: true }, (err, doc) => {
      if (err) {
        console.debug('error.');
      }
    });
    console.timeEnd('test')
    expect(clientUpdated.dbServer).toBe('myServer');
  }, 10000)

The answer is : it’s null, but if i change clientUpdated.dbServer to clientUpdated, it’s not null, but it doesn’t work…

Any idea? :slight_smile:

DW.