lundi 27 juin 2016

IntegrationTest with SuperTest expects 302 gets 200 in Sails.js application

I'm trying to write a simple Test for my Controller. I use this documentation from Sails.js

The UserController.test.js:

var request = require('supertest');

describe('UserController', function () {

    describe('#login()', function () {
        it('should redirect to / indexpage', function (done) {
            request(sails.hooks.http.app)
                .post('/login')
                .send({name: 'Stifflers', password: 'Mom'})
                .expect(302)
                .expect('Location', '/', done);
        });
    });

});

The relevant code from AuthController.js:

...
   // is authenticated
      res.writeHead(302, {
        'Location': "/"
       });

       res.end(); 
...

I run the test with npm test and get this error:

Error: expected 302 "Found", got 200 "OK"

When I change the .expect(302) in my test to .expect(200) I get the next error:

Error: expected "Location" header field

I have tried to do it the same like in the documentation, why doesn't it work?

Aucun commentaire:

Enregistrer un commentaire