Skip to content
Helpers for testing Passport strategies with the Chai assertion library.
JavaScript Makefile
Find file
Latest commit 8cc5517 @jaredhanson 1.0.0
Failed to load latest commit information.
lib Improve JSDoc.
test Clarify test cases.
.gitignore Improve JSDoc.
.jshintrc Update support files.
.npmignore Update support files.
.travis.yml Update support files.
LICENSE Simplify tests.
Makefile Update support files. Update badges.
package.json 1.0.0


Build Coverage Quality Dependencies

Helpers for testing Passport strategies with the Chai assertion library.


$ npm install chai-passport-strategy


Use Plugin

Use this plugin as you would all other Chai plugins:

var chai = require('chai');


Implement Test Cases

Once used, the chai.passport.use helper function will be available to set up test cases for Passport strategies.

The helper function can be called from a hook to setup the test case. The helper returns a wrapper on which callbacks are registered to be executed when the strategy invokes its final action function. The callbacks correspond to Passport's strategy API: success(), fail(), redirect(), pass(), and error(). If the strategy invokes an action that doesn't have a registered callback, the test helper will automatically throw an exception.

The following demonstrates a Mocha test case, taken from passport-http-bearer's test suite.

describe('token strategy', function() {

  var strategy = new Strategy(function(token, done) {
    if (token == 'vF9dft4qmT') { 
      return done(null, { id: '1234' }, { scope: 'read' });
    return done(null, false);

  describe('handling a request with valid credential in header', function() {
    var user
      , info;

    before(function(done) {
        .success(function(u, i) {
          user = u;
          info = i;
        .req(function(req) {
          req.headers.authorization = 'Bearer vF9dft4qmT';

    it('should supply user', function() {

    it('should supply info', function() {



The test suite is located in the test/ directory. All new features are expected to have corresponding test cases. Ensure that the complete test suite passes by executing:

$ make test


The test suite covers 100% of the code base. All new feature development is expected to maintain that level. Coverage reports can be viewed by executing:

$ make test-cov
$ make view-cov



This software is provided to you as open source, free of charge. The time and effort to develop and maintain this project is dedicated by @jaredhanson. If you (or your employer) benefit from this project, please consider a financial contribution. Your contribution helps continue the efforts that produce this and other open source software.

Funds are accepted via PayPal, Venmo, and other methods. Any amount is appreciated.


The MIT License

Copyright (c) 2013-2016 Jared Hanson <>

Something went wrong with that request. Please try again.