Mocha-phantomjs Test Case For Callback Function
I have a module in which I have this function flickrPhotoSearch: function (searchByName, flickrUserKey, numberOfImages, callbackData) { return $.ajax({ url: commonConst
Solution 1:
What you describe is the typical symptom for a test that is asynchronous but is being tested synchronously. The solution is to use the done
callback in your test:
it("should fail with wrong key", function(done) {
flickrApplication.flickrPhotoSearch(testConstant.CORRECT_NAME, testConstant.WRONG_KEY, testConstant.CONSTANT_ONE, handleData);
functionhandleData(photoUrl) {
assert.equals(photourl.stat, "pass", photoUrl.message);
done();
}
});
When you add the done
argument to the callback you give to it
, you tell Mocha that the test is asynchronous and then you must call it in your asynchronous callback (handleData
here) to tell Mocha that the test is over.
Otherwise, Mocha will run the callback given to it
and won't wait for handleData
to execute. The test will end right away, without errors, so Mocha will say it has passed.
Post a Comment for "Mocha-phantomjs Test Case For Callback Function"