Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async example possibly wrong? #1

Open
reallymello opened this issue Dec 29, 2022 · 0 comments
Open

Async example possibly wrong? #1

reallymello opened this issue Dec 29, 2022 · 0 comments

Comments

@reallymello
Copy link
Contributor

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');
      });
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant