Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 您将如何模拟/订阅快速路线请求?_Javascript_Node.js_Unit Testing_Sinon_Chai - Fatal编程技术网

Javascript 您将如何模拟/订阅快速路线请求?

Javascript 您将如何模拟/订阅快速路线请求?,javascript,node.js,unit-testing,sinon,chai,Javascript,Node.js,Unit Testing,Sinon,Chai,例如,如果我想在这个给定的方法中模拟一个req.body,我该怎么做 app.get('/test', exposeDb, function(req, res) { req.dbService.getUserByID(req.body, function(err, result) { if (result == 5) { console.log(result); res.json({result: result});

例如,如果我想在这个给定的方法中模拟一个req.body,我该怎么做

app.get('/test', exposeDb, function(req, res) {
    req.dbService.getUserByID(req.body, function(err, result) {
        if (result == 5) {
            console.log(result);
            res.json({result: result});
        }
        else {
            console.log(result);
            res.json({result: result});
        }
    });
});
以下是我目前的测试:

describe('Test', function() {
    beforeEach(function() {
        var getUserByIDStubE = sinon.stub(dbService, 'getUserByID').callsFake(cb => {
            cb(undefined, 5);
        });


      });

    it('TESTSETSTETS', function(done) {        
        chai.request(server)
            .get('/test')
            .send({ req })
            .end(function (err, res) {
                res.body.result.should.equal(5);
                done();
            });
    });
我想模拟一个req.body,以便将其传递到路由调用中

谢谢


请注意,我正在使用chai http,sinon作为存根。

您希望
req.body
包含什么?您希望
req.body
包含什么?