'How to properly test mocked body by nock?

I'm using Express.js for my backend server. I would like to add various of the tests scenarios to my application.

For this purpose, I use Nock, Chai, Chai-Nock and Supertest. Most of the scenarios pass, however I would like to test particular body of the request that I'm calling directly in my Express.js application.

Frontend -> Express.js -> ( I would like to this this body ) -> 3rd Server.

This is my code:

it('response body is correct', async () => {
    const scope = nock('https://stackoverflow')
      .put(`/author/${authorId}`)
      .reply(200, { name: 'Author_name', surname: 'Author_surname' });

    const res = await request(app)
      .put(`/my-app/author`)
      .send({ authorName: 'Author_name', authorId: 'my-author-id' });
      
    expect(res.status).to.equal(200); // this works
    expect(res.body).to.equal({ name: 'Author_name', surname: 'Author_surname' }); // this works
    
    return expect(scope).to.have.been.requestedWith({ 
       authorName: 'Author_name', 
       authorId: 'my-author-id' 
    }); // this does not work!
  });

I'm following chai-nock documentation https://github.com/chrisandrews7/chai-nock#requestedwithbody. I'm getting

Timeout of 2000ms exceeded. 
For async tests and hooks, ensure "done()" is called; 
if returning a Promise, ensure it resolves


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source