1

I am trying to test the failure functionality of my ajax code (link).

I am using the latest versions of Karma, PhantomJS, and Jasmine with all required plugins.

The test run with success in Chrome but when I use PhantomJS my ajax fail tests do not call the fail or the success functions. I added a success for debug purposes not in the code below. The proper before and afters have been setup as well since all other ajax test work as expected, just the request is not failing as needed.

Here is a snippet of my test.

it("Check sample response of fail", function() {
    var fail = jasmine.createSpy("getJSON fail");

    app.getJSON(testUrl).fail(fail);

    jasmine.Ajax.requests.mostRecent().respondWith({
        status: 500,
        statusText: "error",
        contentType: "text/plain",
                responseText: ""
    });

    expect(fail).toHaveBeenCalled();
    expect(fail.calls.mostRecent().args[0]).toBe("error");
    expect(fail.calls.mostRecent().args[1]).toBe(500);
});
Cobra_Fast
  • 15,671
  • 8
  • 57
  • 102
ClearBucket
  • 45
  • 1
  • 7

0 Answers0