Answer the question
In order to leave comments, you need to log in
How to mock services (including built-in ones) for other services in Angular?
There is some simple module with a simple service:
// my.mdl.js
import angular from 'angular';
import myService from './services/my';
const myMdl= angular.module('module', []);
myMdl.factory(myService.name, myService);
export default myMdl;
// services/my.js
export default function myService ($q, anotherModuleService) {
return {
someFunc () {}
}
}
// my.spec.js
import mocks from 'angular-mocks';
import myMdl from './my.mdl';
describe('myModule', () => {
beforeEach(mocks.module(myMdl.name));
describe('myModuleService', () => {
let service;
beforeEach(mocks.inject((myService) => { // LINE A
service = myService;
}));
it('has expected method', () => {
expect(service.someFunc).toEqual(jasmine.any(Function));
});
});
});
$q
and anotherModuleService
. This is probably done somewhere in the LINE A area.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question