2011-05-24 49 views
2

我正在學習使用sinon與nodeunit,特別是做嘲弄。 recommended approach將使用sinon-nodeunit。根據the documentation,對於每個測試函數,應該通過test參數的mock方法提供模擬。使用sinun mocks與nodeunit

但是,這似乎並不奏效。如果我的包含文件運行nodeunit以下 -

require('sinon-nodeunit'); 

exports['test sinon-nodeunit'] = function (test) { 
    mock = test.mock({}); 
    test.done(); 
}; 

- 我得到這樣的:

$ nodeunit test/test-sinon-nodeunit.js 

test-sinon-nodeunit.js 
✖ test sinon-nodeunit 

TypeError: Object #<Object> has no method 'mock' 
    at /home/malkovich/test/test-sinon-nodeunit.js:4:17 
    at Object.runTest (/usr/local/lib/node/.npm/nodeunit/0.5.1/package/lib/core.js:54:9) 
    at /usr/local/lib/node/.npm/nodeunit/0.5.1/package/lib/core.js:90:21 
    at /usr/local/lib/node/.npm/nodeunit/0.5.1/package/deps/async.js:508:13 
    at /usr/local/lib/node/.npm/nodeunit/0.5.1/package/deps/async.js:118:13 
    at /usr/local/lib/node/.npm/nodeunit/0.5.1/package/deps/async.js:134:9 
    at /usr/local/lib/node/.npm/nodeunit/0.5.1/package/deps/async.js:507:9 
    at Object.concatSeries (/usr/local/lib/node/.npm/nodeunit/0.5.1/package/deps/async.js:147:23) 
    at Object.runSuite (/usr/local/lib/node/.npm/nodeunit/0.5.1/package/lib/core.js:79:11) 
    at Object.runModule (/usr/local/lib/node/.npm/nodeunit/0.5.1/package/lib/core.js:114:13) 


FAILURES: 1/1 assertions failed (84ms) 

我已經安裝了sinon(1.1.1)的最新版本和sinon-nodeunit(0.1.2 )通過npm install

回答

2

require.path在節點0.5.x和更高版本中刪除,這是sinon-nodeunit使用的。 Christian Johansen推動了sinon-nodeunit的變化,它應該與節點0.6.2(和0.5.x系列)兼容,它應該解決這個問題......它已經在sinon-nodeunits github頁面上提供,但仍然沒有命中npm。 ..

更新:應該提到的是,sinon-nodeunit已經停止,因爲創建者完全專注於BusterJS,而IMHO是一個更好的框架。