Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To receive a status code of 204 instead of 200 using Auth0 and Supertest, you can modify your test case to include an assertion that checks for the status code. Here's an example:

const request = require('supertest');
const app = require('../app');

describe('GET /users', () => {
  it('returns a 204 status code', (done) => {
    request(app)
      .get('/users')
      .set('Authorization', 'Bearer YOUR_AUTH0_ACCESS_TOKEN')
      .expect(204)
      .end((err, res) => {
        if (err) return done(err);
        done();
      });
  });
});

In this example, we're sending a GET request to the /users endpoint with an Auth0 access token. We're also expecting a status code of 204 in the response. If the status code is not 204, Supertest will throw an error and the test will fail.

Make sure to replace YOURAUTH0ACCESS_TOKEN with an actual access token from your Auth0 application.