0.2.2 • Published 7 years ago

next-stub v0.2.2

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

next-stub

Unit test middleware by replacing next() with a callback

const stub = require('../index')
const chai = require('chai'),
    expect = chai.expect

chai.config.includeStack = true
 
let req = {body: {user: "bob"}}
    res = {locals: {}}
 
let middlewareBob = function (req, res, next) {
    res.locals.user = req.body.user.toUpperCase()
    next()
}

let middlewareErr = function (req, res, next) {
    if (req.body.user !== "bleh") {
        next(Error('bob is not bleh'))
    }
}

describe('middleware next is stubbed', () => {
    it('req and res work when next called with no arg', () => {

        stub(middlewareBob, req, res, function (err, req, res) {
            expect(res.locals.user).to.equal('BOB')
            expect(err).to.not.exist
        })

    })

    it('err handled if arg passed to next', () => {

        stub(middlewareErr, req, res, function (err, req, res) {
            expect(err).to.exist
        })

    })
})
0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago