在NodeJs中使用mocha进行模拟

rav*_*don 17 mocking mocha.js node.js

如何使用NodeJ在Mocha中模拟客户端和服务器.具体来说,我有以下代码:

app.post ('path name', function (req, res) { 
  // Some Action 
  res.send(response); 
});
Run Code Online (Sandbox Code Playgroud)

我想模拟req,res参数和测试res(状态,标题,消息).

Pet*_*ons 19

Mocha本身不提供模拟/存根/间谍类型功能.Sinon是一个受欢迎的图书馆.主页包括测试ajax及其Fake XMLHTTPRequest对象的示例.