1

This test:

it("getFooCount success", function () {
    httpBackend.whenGET('/api/getFooCount').respond(1);

    fooService.getFooCount();
    httpBackend.flush();
    expect(fooService.FooCount).toBe(1);
});

fails: "Expected null to be 1" (fooService.fooCount is null before the api get method is called).

Yet this test passes:

it("getFooCount success", function () {
    httpBackend.whenGET('/api/getFooCount').respond("1");

    fooService.getFooCount();
    httpBackend.flush();
    expect(fooService.fooCount).toBe("1");
});

It seems to be able to pass the test with anything (an object, string, array, etc) EXCEPT a number in the .respond().

The api I am calling just returns an integer, any advice as to how I can get this to work, and/or why it is failing?

lwalden
  • 813
  • 7
  • 11
  • It's possible you need to call $digest on the scope to see the change, there might be an odd reason why that's only an issue with numbers – Peter Ashwell Dec 30 '14 at 03:27

1 Answers1

3

Have a look at the API for respond, because the first argument is actually the status code.

Try instead respond(200, 1).

Angularjs seems to smart its way around when you provide a non statist object as first parameter

Peter Ashwell
  • 4,292
  • 2
  • 18
  • 22