JavaScript的模擬測試庫:MoqJS

cm54 9年前發布 | 12K 次閱讀 MoqJS 單元測試

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.baiduhome.net/lib/view/home/1428544223901

 本文由用戶 cm54 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!