小编act*_*203的帖子

使用promise时mocha js断言挂起?

"use strict";
let assert = require("assert");

describe("Promise test", function() {
  it('should pass', function(done) {
    var a = {};
    var b = {};
    a.key = 124;
    b.key = 567;
    let p = new Promise(function(resolve, reject) {
        setTimeout(function() {
            resolve();
        }, 100)
    });

    p.then(function success() {

        console.log("success---->", a, b);
        assert.deepEqual(a, b, "response doesnot match");
        done();
    }, function error() {

        console.log("error---->", a, b);
        assert.deepEqual(a, b, "response doesnot match");
        done();
    });
 });
});
Run Code Online (Sandbox Code Playgroud)

输出: 输出结果

我使用的是节点v5.6.0.当值不匹配时,测试似乎挂起断言.

我尝试使用setTimeout检查assert.deepEqual是否存在问题,但它工作正常.

但是在使用Promise时失败并在值不匹配时挂起.

javascript bdd assert mocha.js node.js

5
推荐指数
1
解决办法
1252
查看次数

标签 统计

assert ×1

bdd ×1

javascript ×1

mocha.js ×1

node.js ×1