小编ber*_*unt的帖子

使用Mocha测试Promise-chains

我有以下样式的函数(在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)

javascript unit-testing mocha.js node.js bluebird

14
推荐指数
1
解决办法
5465
查看次数

标签 统计

bluebird ×1

javascript ×1

mocha.js ×1

node.js ×1

unit-testing ×1