No expected requests with angular-mock, $resource and ionic


Heya, I’m having trouble getting angular-mocks in tests to work correctly. I am testing a little service:

    .factory('FooService', function($resource) {
        return {
            getFoo: function() {
                var fooResource = $resource('http://localhost:8081/foos', {}, {
                    get: {method: 'GET'}

                return fooResource.get();

and would expect the following test

describe('Foo Service', function () {

    it('makes a request', function () {
        this.FooService.getFoo().$promise.then(function (result) {
            console.log('result: ', result);

to return me an error message like this:

Error: Unexpected request: GET http://localhost:8081/foos

But unfortunately I get nothing and the test would not tell me that there was a request. However, when I add an $httpBackend.flush() after the promise success function it will give me the unexpected request error that I want. Of course this is not the behavior I want and am used from angular.

I am using ionic 1.1.0 with angular 1.4.3.


files: [

I also tried not using the ionic.bundle file and including the dependencies (making sure all dependencies except angular-ui-router are also 1.4.3) into the karma.conf with no success.


files: [



Has anybody had any success with getting angular-mocks to work properly with $http/$resource in ionic? Or does anybody know of a good example/tutorial? Thanks for any help


Hmm okay, maybe I was wrong about my assumptions. I guess I was using a lot of $http calls that were triggered via ui interactions like click() that trigger digests and by that the flush gets invoked implicitly?

I just tried a plain angular example and also did not receive an unexpected request when not explicitly asking for it.