Search code examples
node.jssupertest

supertest: test the redirection url


with supertest, I can test the redirection code 302

var request = require('supertest');
var app = require('../server').app;

describe('test route', function(){
  it('return 302', function(done){
    request(app)
      .get('/fail_id')
      .expect(302, done);
  });
  it('redirect to /');
});

how I can test the url objetive to redirect ?


Solution

  •   it('redirect to /', function(done){
        request(app)
          .get('/fail_id')
          .expect('Location', /\//, done);
      });