使用QUnit测试,在async()断言中断言测试失败

时间:2017-11-30 09:25:30

标签: javascript tdd qunit

我正在使用TDD测试我的代码。

代码如下 -

 QUnit.test("Testing submitApi", function (assert) {
        //  createSampleSheet();          
        BWUser.authenticate().done(function () {
            BWTableProperties.readAllTableProperties().then(function (allTableProperties) {

                for (var i = 0; i < allTableProperties.length; i++) {                        
                    var getResult = Submit.submitApi(allTableProperties[i], "test", 0); //getResult is Promise
                    getResult.then(function () {
                        var promise = assert.async();
                        var promisedone = makeQuerablePromise(getResult);// gives whether promise resolved or not
                        promisedone.then(function () {

                            assert.equal(promisedone.isFulfilled(), true, "Promise should be resolved");
                            promise();
                        });
                    });                     
                }

            });
        });
    });

当我运行测试时,它显示以下错误:

  

Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.

任何人都可以提出这里出了什么问题,第一印象我觉得因为for循环可能会有错误,但我不确定。 ?

1 个答案:

答案 0 :(得分:1)

当你已经在异步代码中时,你正在调用assert.async。如果您在测试开始时调用它,在调用异步代码之前,测试将等待promise()调用。

相关问题