Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

mock-session

0.0.5 • Public • Published

mock-session

Create required session object for testing, which is used with cookie-session.

If you are using mocha + express + cookie-session and you need to set desired session object in tests or somewhere than this packge can be helpful.

npm install mock-session

mockSession('Session name of cookie-session',    
            'first key of cookie-session',      
            'data you need to add in session'     
          );

Example

let mockSession = require('mock-session');
let cookie = mockSession('my-session', 'my-secret', {"count":1});   
.
.
.
await request(app).get('api/images/create')
        .set('cookie', [cookie])
        .expect(200);

Controller Side: You'll receive session object like this

exports.create = function(req, res) {         
  if(req.session.count == 1) { // true                      
    //do something                
    res.sendStatus(200);                    
  }
}

install

npm i mock-session

Downloadsweekly downloads

18

version

0.0.5

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability