1

So, I learn to make a TDD. I have a simple API with NodeJS using Express Framework. This API only gives redirect function

router.route('/')
    .get(function(req, res, next) { 
        res.status(200)
        res.redirect('/Login')
    })
    .post(function(req, res, next) {

    });

My Question is how to make unit test using mocha chai based on this API?
I'm trying to do something like this, but it passed even though I give 400 statuscode in the test

var app = require('../routes/index');

var should = require('chai').should(),
    expect = require('chai').expect,
    supertest = require('supertest'),
    api = supertest('http://localhost:3030');

describe('/ ', function() {
    it('Should redirect to /Login ', function() {
        api.get('/') 
            .expect(400)
                    .end(function(err, res) { 
                        expect(res.statusCOde).to.equal(400); 
                        done();
                    })
    })
})
yogieputra
  • 637
  • 2
  • 14
  • 28
  • Read this : http://stackoverflow.com/questions/12272228/testing-requests-that-redirect-with-mocha-supertest-in-node . It works with should so it should work with chai – jy95 Mar 14 '17 at 19:41
  • @jacquesy thanks man for the reference, I am now reading it – yogieputra Mar 14 '17 at 20:04

0 Answers0