Set authentication token to chai-Http
<p>I have created some test cases in node express framework which return successfully. However there are some API calls which need to have authenticated before I can make them. I can call the API that requires authentication in reactJs via ajax and It give a success response, however when I set the same header in chai-Http, it fails with <code>invalid token</code>.</p>

<pre><code>var chai = require('chai');
var should = chai.should();
var chaiHttp = require('chai-http');

chai.use(chaiHttp);
var server = require('../app');   

describe('routes : index', function() {
var token = '';
beforeEach(function(done) {
     done();
});
before(function(done) {
    chai.request(server)
        .post('/doSignin')
        .send({uname:'ruzan@test.com',password:'123123'})
        .end(function(err, res) {
            res.redirects.length.should.equal(0);
            res.status.should.equal(200);
            token = res.body.user.token;
            res.type.should.equal('application/json');
            done();
        });
});

afterEach(function(done) {
    done();
});

describe('Test FolderController', function() {
    it('should list all the folders', function(done) {
        console.log(token); // here it print the same token
        chai.request(server)
            .get('/notes/get-notes')
            .set('prg-header' , token)
            .end(function(err, res) {
               // console.log(res);
                res.status.should.equal(200);
                done();
            });
    });
});
});
</code></pre>

<p>ReactJs:</p>

<pre><code>$.ajax({
        url: '/notes/get-notes',
        method: "GET",
        dataType: "JSON",
        headers: { 'prg-header':loggedUser.token }
    }).done( function (data, text) {
        console.log(data);
        if(data.status.code == 200){
            // it come here the data
        }
    }.bind(this));
</code></pre>