supertest icon indicating copy to clipboard operation
supertest copied to clipboard

Which methods trigger the execution of the request?

Open john-doherty opened this issue 5 years ago • 0 comments

Hey everyone. I'm trying to understand which methods trigger the execution of the request based on the examples:

Calling .end() makes sense:

describe('POST /users', function() {
  it('responds with json', function(done) {
    request(app)
      .post('/users')
      .send({name: 'john'})
      .set('Accept', 'application/json')
      .expect('Content-Type', /json/)
      .expect(200)
      .end(function(err, res) {
        if (err) return done(err);
        done();
      });
  });
});

In the example below, is execution triggered by passing a function to the last expect?

describe('GET /user', function() {
  it('responds with json', function(done) {
    request(app)
      .get('/user')
      .set('Accept', 'application/json')
      .expect('Content-Type', /json/)
      .expect(200, done);
  });
});

Which method triggers the execution when using promises?

describe('GET /users', function() {
  it('responds with json', function() {
    return request(app)
      .get('/users')
      .set('Accept', 'application/json')
      .expect('Content-Type', /json/)
      .expect(200)
      .then(response => {
          assert(response.body.email, '[email protected]')
      })
  });
});

john-doherty avatar Jun 03 '20 20:06 john-doherty