mardi 29 mars 2016

$resource Callback not Being Invoked Angular

I have a method which makes a call to Angular's $resource. I am trying to test the return value of this method. This method should be simple enough to test.

Method Code

getCountries(): any {
        var this.$resource(
            this.apiEndpoint.baseUrl,
            {
                'get': {
                    method: 'GET', isArray: false
                }
            });
        return countries;
    }

Unit Test

describe('module', (): void => {
    var $resource;

    beforeEach((): void => {
        angular.mock.module('ngResource');
    });

    describe('getCountries...', (): void => {

        it("should...", inject(
            ['Builder', (Builder: IBuilder): void => {
                Builder.getCountries().get(
                    (value: any) => {
                        console.log(value);
                    }, (error: any) => {
                        console.log(error);
                    });
            }]));
    });

});

Now in the above code when I run my test the none of the callbacks ever get called. Neither "value" nor "error" ever can printed. I've been looking for a solution for quite a while now but haven't been able to find anything.

Keep in mind that I do not want to mock $resource, instead I want to test what is returned by getCountries().get() and then I want to use the callbacks to test the return value.

Aucun commentaire:

Enregistrer un commentaire