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

assert test failed in async() assertion with QUnit testing

我正在使用 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 循环可能会有错误,但我不确定。 ?

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