我有以下样式的函数(在Node.JS下使用bluebird promises):
module.exports = {
somefunc: Promise.method(function somefunc(v) {
if (v.data === undefined)
throw new Error("Expecting data");
v.process_data = "xxx";
return module.exports.someother1(v)
.then(module.exports.someother2)
.then(module.exports.someother3)
.then(module.exports.someother4)
.then(module.exports.someother5)
.then(module.exports.someother6);
}),
});
Run Code Online (Sandbox Code Playgroud)
我正在尝试测试(使用mocha,sinon,断言):
// our test subject
something = require('../lib/something');
describe('lib: something', function() {
describe('somefunc', function() {
it("should return a Error when called without data", function(done) {
goterror = false;
otherexception = false;
something.somefunc({})
.catch(function(expectedexception) {
try {
assert.equal(expectedexception.message, 'Expecting data');
} catch (unexpectedexception) {
otherexception = unexpectedexception;
}
goterror = true;
}) …Run Code Online (Sandbox Code Playgroud)