nightwatchjs / nightwatch-plugin-apitesting

Run API tests in Nightwatch using supertest
https://nightwatchjs.org
MIT License
2 stars 8 forks source link

Async example possibly wrong? #1

Open reallymello opened 1 year ago

reallymello commented 1 year ago

Following the The README documentation of an async test against a mockserver and trying to apply that to remote API I'm finding it doesn't run the assertions (doesn't await?).

Here is the example from the README

it('demo test', async function(client) {
    const req = await server.request()
      .post('/api/v1/datasets/')
      .send({name: 'medea'})
      .set('Accept', 'application/json')
      .expect(200)
      .expect('Content-Type', /json/);

    await client.assert.deepStrictEqual(server.route.post('/api/v1/datasets/').requestBody, {name: 'medea'});
  });

If I modify that to talk to a remote API like the demo Swagger Petstore API it doesn't await on the expects so it will pass regardless of the expect

it('pet store test', async function({supertest}) {
    const req = await
      supertest
        .request('https://petstore.swagger.io/v2')
        .get('/store/inventory')
        .set('Accept', 'application/json')
        .expect(200) // For example, if I change this to 400 it will still pass
        .expect('Content-Type', /json/);
  });

If I instead use a non-async pattern it correctly checks the assertions

it('pet store test2', function({supertest}) {
    supertest
      .request('https://petstore.swagger.io/v2')
      .get('/store/inventory/')
      .expect(200) // If I change to 400 it will fail as expected
      .expect('Content-Type', /json/)
      .end(function() {
        console.log('done');
      });
  });