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 ?
@JuanPablo's answer is on the right path (pun intended), but it will match any location with /
anywhere.
You want to make sure that there is nothing following the /
by using the line-end char $
, and that the chars previous to the /
are what you expect. A quick-and-dirty example follows:
it('redirect to /', function(done){
request(app)
.get('/fail_id')
.expect('Location', /\.com\/$/, done);
});
it('redirect to /', function(done){
request(app)
.get('/fail_id')
.expect('Location', /\//, done);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With