Search code examples
javascripttddqunit

assert test failed in async() assertion with QUnit testing


I am Testing My code Using TDD.

code is as follow -

 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();
                        });
                    });                     
                }

            });
        });
    });

when i Run the test it shows following Error :

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

can anybody suggest what went wrong here, first impression i feel that because of for loop there may be error but i'm not sure. ?


Solution

  • You're calling assert.async when already inside asynchronous code. If you call it at the beginning of the test, before the call to the async code, the test will wait for the promise() call.