JavaScript的模拟测试库:MoqJS

cm54 10年前

MoqJS 是一个受.NET Moq 框架启发的 JavaScript 测试库。

MoqJS提供了以下特性:

  • Strong-typed: was developed in TypeScript.
  • Unsurpassed VS intellisense integration: everything supports full VS intellisense, from setting expectations, to specifying method call arguments, return values, etc.
  • Use setup/setupPrivate/verify/verifyPrivate to change and check the moles behavior.
  • VERY low learning curve as a consequence of the previous three points.
  • Control over mock behavior with a simple callBase/isStrict properties
  • Find moles by instance of the moled object.
示例代码:
// Create some object instance  var dog = new Dog();     // Create a mole for the object  var mole = new Mole(dog);     // Setup behavior  mole.setup(_dog => _dog.eat('meat')).returns('Yum yum yum');     // Invoke  var result = dog.eath('meat');     // Verify the given method was indeed called with the expected value exactly once  var isVerified = mole.verify(_dog => _dog.eat('meat'), Times.exact(1));

项目主页:http://www.open-open.com/lib/view/home/1428544223901