如何使用jasmine-node在Node.js中模拟seneca调用?

我使用express模块​​,下面是app.js的代码

app.post('/test_url', function(request, response){ seneca.client({type: 'http',port: '3000',host: 'localhost',protocol: 'http'}).act({role: 'sample_role', cmd: 'save',firstname: request.params.firstname}, function (err, result) { console.log("Inside Seneca act"); response.json(result); }) }); 

以下是我正在编写上述代码的testing用例的testing文件。

 describe("POST /test_url/:firstname", function() { it("should return status code 200", function(done) { <b>//here I want to mock the call for seneca.client so that I can test if the call has been made with the required parameters.</b> <b>//Also I would like to use the above mock object to further mock the call for act so that I can check if the act method has been called with the required parameters.'</b> //Main purpose behind doing so is that I do not want the seneca methods to get actually called, and only want to test if the call has been made. request.post("http://localhost:3000/test_url/sara", function(error, response, body) { //some verification method on the mock object so as to confirm that both the calls ie 'seneca.client' and 'seneca.client().act' have been called with the appropriate parameters expect(body).toContain("success"); done(); }); }); }); 

我试图用jasmine spy和sinon来模拟seneca调用,但是仍然调用实际上正在去的方法,并且调用了callback函数,导致console.log(“Inside Seneca act”); 被称为,这不是我所期望的。

 describe("POST /test_url/:firstname", function() { it("should return status code 200", function(done) { var senecaCall = sinon.stub(seneca, 'client'); //or spyOn(seneca, "client"); request.post("http://localhost:3000/test_url/sara", function(error, response, body) { expect(body).toContain("success"); done(); }); }); });