Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 974 Bytes

README.md

File metadata and controls

43 lines (32 loc) · 974 Bytes

express-test-util

test utils for express middlewares (which must call next)

Installation

$ npm install --save express-test-util

Usage

const config = require('config');
const expect = require('chai').expect;
const util = require('express-test-util');

const middleware = function (req, res, next) {
    res.cookie('key', 'value');
    next();
};

describe('#default', function () {
    it('should use req.param.city when exists', function (done) {
        const req = util.mockRequest({ params: { city: 'bj' }, props: { cityList } });
        const res = util.mockResponse();

        middleware(req, res, function (err) {
            if (err) {
                return done(err);
            }

            expect(req.param('city')).to.equal('bj');
            expect(res.cookies.key).to.deep.equal({ value: 'bj', options: {} });
            done();
        });
    });

});

License

Apache-2.0 © wangshijun