javascript - How to return mock json object from file as service response in Angular JS Jasmine Unit Test? -
i referring stackoverflow article how mock service returns promise in angularjs jasmine unit test?. , found useful in scenario well. want load , return object json file mock instead of explicit object. possible achieve that?
i referring below response:
describe('testing method() on service', function () { var mock, service function init(){ return angular.mock.inject(function ($injector,, _serviceundertest_) { mock = $injector.get('service_that_is_being_mocked');; service = __serviceundertest_; }); } beforeeach(module('yourapp')); beforeeach(init()); it('that has then', function () { //arrange var spy= spyon(mock, 'actionbeingcalled').and.callfake(function () { return { then: function (callback) { return callback({'foo' : "bar"}); } }; }); //act var result = service.actionundertest(); // cleverness //assert expect(spy).tohavebeencalled(); }); });
Comments
Post a Comment