相关疑难解决方法(0)

表达中间件测试摩卡柴

有没有办法在Express中测试那种中间件:

module.exports = function logMatchingUrls(pattern) {
    return function (req, res, next) {
        if (pattern.test(req.url)) {
            console.log('request url', req.url);
            req.didSomething = true;
        }
        next();
    }
}
Run Code Online (Sandbox Code Playgroud)

我发现的唯一中间件测试是:

module.exports = function(request, response, next) {
    /*
     * Do something to REQUEST or RESPONSE
    **/

    if (!request.didSomething) {
        console.log("dsdsd");
        request.didSomething = true;
        next();
    } else {
        // Something went wrong, throw and error
        var error = new Error();
        error.message = 'Error doing what this does'
        next(error);        
    }
};


describe('Middleware test', function(){

    context('Valid arguments are …
Run Code Online (Sandbox Code Playgroud)

mocha.js node.js express

15
推荐指数
1
解决办法
8169
查看次数

标签 统计

express ×1

mocha.js ×1

node.js ×1