I want to test that my web app handles a failure scenario and displays the corresponding error message using QUnit.
My app performs a JSONP request to get its initialization contents. I want to test the case where my Data Source is unavailable upon startup. This scenario results in an error on the underlying JQuery code, which I believe QUnit is intercepting and capturing it as a failed assertion, even though that is the expected behavior.
My app code looks like this:
loadContents() {
$.ajax({
url: initURL,
dataType: 'jsonp',
timeout: timeout,
success: initializeDisplay,
error: displayErrorMessage,
});
}
My test case looks like this:
asyncTest("Invalid initialization host", 1, function() {
initURL = invalidURL;
loadPageContents();
index = $("#error-message-div").text().indexOf(errorMessage);
ok(index > -1, "Error message not found");
})
When I run my test, I get an extra assertion, which always fails. The assertion contains the message: "Error loading script" with a URL to the JSONP GET request.
The issue I believe I am running into is that since the JSONP callback is never executed, it throws an exception which QUnit believes to be a failed assertion.
Any ideas how I could get my test to execute without registering the exception as a failure?
Update -
To clarify, the QUnit assertion works as expected, however I am somehow getting an additional assertion, which fails always.
Thanks!