I've been tasked with setting up some "Integrated Tests" (not "Unit Tests" or "UI tests" [aka. E2E/Protractor]). This integrated test is doing nothing more than testing the controller's $http POST request to the external API, and checking for an expected response case.
I've tried this: - no ngMock (should connect directly to http resources); - with ngMock (couldn't get through to http resource because passThrough() was undefined); - finally tried with ngMockE2E, passThrough() is supposedly working, but the request doesn't return either of success() or error().
I've tried $httpBackend.flush()
and it says "there are no request to flush!" (since it is using passThrough() I presume the flush function is not needed).
I've tried $rootScope.$apply()
and that doesn't make any difference.
Not sure how to get this working as expected, is this even possible without using Protractor...? Does anyone even do "integrated tests" for AngularJS apps? It looks like the standard is "unit tests" and "E2E tests", not so much "integrated tests".
The "unit tests" I've got setup use a mocked resource and that calls the success() and error() as expected.
Thoughts/ideas?
[Edit:] Found problem is related to Jasmine async testing. In Jasmine 1.X you need to use run() and waitsFor(), in Jasmine 2.X you can use done() (although I couldn't get 2.X working, it just broke all my tests). So now I'm receiving callback from the $http request but it's always error() being called. Now I have no idea why success() isn't being called. Any ideas?