1

I'm doing a lot of requests and want to see only the status code, there are areas that require to be authenticated to access which want to check.
This isn't a test end-to -end, would not be useful to use the Zombie.js or Nightwatch.js.

Is there any possibility to fill the login form and making requests go after?

3
  • So, you want to test you authentication logic against all your routes using an series of automated requests whose authentication values are derived from a login form? Commented May 30, 2015 at 19:32
  • I wish to make a request in /upload and verify that the return 200 if it isn't authenticated will be redirected. Commented May 30, 2015 at 19:35
  • You could do this with an external unit test. Essentially run two requests against your dev server instance. One with a valid authentication payload (e.g. a test account) and one without a authentication payload. To extract status codes from node http requests see: nodejs.org/api/http.html#http_http_request_options_callback Commented May 30, 2015 at 19:40

1 Answer 1

2

Have you seen Supertest?

npm install supertest --save-dev

You can use this to simulate request and check execution or status code.

var request = require('supertest')
  , express = require('express');

var app = express();

app.get('/user', function(req, res){
  res.send(200, { name: 'tobi' });
});

request(app)
  .get('/user')
  .expect('Content-Type', /json/)
  .expect('Content-Length', '20')
  .expect(200)
  .end(function(err, res){
    if (err) throw err;
  });

With Mocha:

describe('GET /users', function(){
  it('respond with json', function(done){
    request(app)
      .get('/user')
      .set('Accept', 'application/json')
      .expect('Content-Type', /json/)
      .expect(200, done);
  })
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.