mercredi 2 décembre 2015

How to mock ng-sails $sails provider in AngularJS unit test?

I have a method in my controller that has the following structure:

$sails.get(url).success(function(){}).error(function(){})

How do I mock this while writing a unit test case for the controller?

I am using the following library to implement the sails connector: http://ift.tt/1QejEme

This is one method I've tried,

beforeEach(function() {
mockSails = jasmine.createSpyObj('$sails', ['on', 'socket', 'get']); });

    mockSails.get.andReturn({
        success: function() {},
        error: function() {}
     });

While executing the test case, I get the error : Cannot read property 'error' of undefined

How do I fix this?

Aucun commentaire:

Enregistrer un commentaire