2

我正在学习将 sinon 与nodeunit一起使用,专门用于模拟。推荐的方法是使用sinon-nodeunit。根据文档,应该可以通过每个测试函数mock的参数方法使用模拟。test

但是,这似乎不起作用。如果我nodeunit在包含以下内容的文件上运行 -</p>

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我已经sinon-nodeunit通过npm install.

4

1 回答 1

2

在 sinon-nodeunit 使用的节点 0.5.x 及更高版本中删除了 require.path。Christian Johansen 刚刚推动了 sinon-nodeunit 的更改,该更改应该与节点 0.6.2(和 0.5.x 系列)兼容,应该可以解决这个问题......它已经在 sinon-nodeunits github 页面上可用,但仍然没有命中 npm。 ..

更新:应该提到 sinon-nodeunit 已经停产,因为创建者完全专注于 BusterJS,恕我直言,这是一个更好的框架。

于 2011-11-23T12:13:18.670 回答