Daniela Morais
Daniela Morais

Reputation: 2247

How to set values in a form automatically with Node.js

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?

Upvotes: 1

Views: 549

Answers (1)

Luca Colonnello
Luca Colonnello

Reputation: 1456

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);
  })
})

Upvotes: 2

Related Questions