Tuesday 14 March 2017

How to make TDD with simple redirect page function API

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



via Liverpool

No comments:

Post a Comment