rit-sse / node-api

💯 The SSE New and Improved Unified API
https://sse.rit.edu/api/v2
MIT License
8 stars 9 forks source link

Update supertest/chai tests to use return Promise syntax to avoid timeouts #102

Closed gavrielrh closed 4 years ago

gavrielrh commented 4 years ago

Updates all async tests to avoid using done() when possible, as supertest/chai now handles async properly as long as you return the request/promise. This mitigates the timeout issues where tests are perceived as passing/failing because the previous test times out (waiting on a resolve that'll never happen as it's in a reject state).

Example from https://github.com/visionmedia/supertest

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, 'foo@bar.com')
      })
  });
});

An alternative is to use .end((err, res) => {...} where you handle the err case and return done(err) and if success, return done() but this is almost as messy as it was before, and complicates the tests using Promise.all(...)