Has anyone been able to build specs or e2e tests using $httpBackend while having BreezeJS function as your entity manager?
Here is the BreezeJS code:
function getClientsAll() {
var query = breeze.EntityQuery.from('clients').using($clientJsonResultsAdapter);
return em.executeQuery(query);
}
And here is the test code from the Jasmine Spec using AngularJS $httpBackend:
it('should show all clients', function() {
$httpBackend.expectGET(/clients/).respond([ 200, mockData.clients.GET]);
backupModelService.getClientsAll()
.then(function() {
console.log("getClientsAll success");
})
.fail(function() {
console.log("getClientsAll fail");
})
$httpBackend.flush();//error thrown here
});
But I get the jasmine test failure
Error: No pending request to flush !
This breeze method works fine running in the browser but not during tests. However, if I convert to using angularJS $http or $resource, this test will pass. I'm wondering if BreezeJS is not compatible with the $httpBackend for spec and e2e testing.
Thanks for any insight.
//EDIT --- AFTER TRYING TO MOCK AJAX BECAUSE OF STEVE'S RESPONSE
This fails as well.
var success = jasmine.createSpy('success');
var fail = jasmine.createSpy('fail');
spyOn($, 'ajax').andCallFake(function (req) {
var d = $.Deferred();
d.resolve(mockData.clients.GET);
return d.promise();
});
backupModelService.getClientsAll()
.then(success)
.fail(fail);
expect(success).toHaveBeenCalled();