admin管理员组

文章数量:1296886

I'm relatively new to unit-testing on the backend and need some guidance as to how to unit-test the following. I'm using Mocha/Should/Sinon.

exports.get = function(req, res) {
   if (req.query.example) {
      return res.status(200).json({ success: true });
   } else {
      return res.status(400).json({error: true});
   } 
}

I'm relatively new to unit-testing on the backend and need some guidance as to how to unit-test the following. I'm using Mocha/Should/Sinon.

exports.get = function(req, res) {
   if (req.query.example) {
      return res.status(200).json({ success: true });
   } else {
      return res.status(400).json({error: true});
   } 
}
Share Improve this question edited May 2, 2017 at 13:56 cusejuice asked May 2, 2017 at 13:41 cusejuicecusejuice 10.7k27 gold badges95 silver badges150 bronze badges 4
  • are you using the “expect” or “should” syntax of chai? – Patrick Hund Commented May 2, 2017 at 14:38
  • Using the should syntax of chai – cusejuice Commented May 2, 2017 at 14:48
  • Aaah… OK, I'll update my answer then

    本文标签: javascriptProperly stubbing requestresponse with SinonMochaStack Overflow