In the scenario below, I am getting the following error which I have no clue why this is occurring. Line 71 is the expect test failing. Any help deciphering what the issue could be would be greatly appreciated!
PhantomJS 2.1.1 (Mac OS X 0.0.0) UserService should be able to create a user service FAILED
_instantiateProvider@/Users/nsmith/projects/cohortable/spec-bundle.js:12308:38 <- webpack:///angular2/src/core/di/injector.ts:769:31
_new@/Users/nsmith/projects/cohortable/spec-bundle.js:12297:42 <- webpack:///angular2/src/core/di/injector.ts:758:37
getObjByKeyId@/Users/nsmith/projects/cohortable/spec-bundle.js:11907:55 <- webpack:///angular2/src/core/di/injector.ts:355:44
_getByKeyDefault@/Users/nsmith/projects/cohortable/spec-bundle.js:12493:51 <- webpack:///angular2/src/core/di/injector.ts:973:44
_getByKey@/Users/nsmith/projects/cohortable/spec-bundle.js:12439:42 <- webpack:///angular2/src/core/di/injector.ts:910:35
_getByDependency@/Users/nsmith/projects/cohortable/spec-bundle.js:12425:35 <- webpack:///angular2/src/core/di/injector.ts:892:28
_instantiate@/Users/nsmith/projects/cohortable/spec-bundle.js:12317:53 <- webpack:///angular2/src/core/di/injector.ts:781:46
_instantiateProvider@/Users/nsmith/projects/cohortable/spec-bundle.js:12308:38 <- webpack:///angular2/src/core/di/injector.ts:769:31
_new@/Users/nsmith/projects/cohortable/spec-bundle.js:12297:42 <- webpack:///angular2/src/core/di/injector.ts:758:37
getObjByKeyId@/Users/nsmith/projects/cohortable/spec-bundle.js:11907:55 <- webpack:///angular2/src/core/di/injector.ts:355:44
_getByKeyDefault@/Users/nsmith/projects/cohortable/spec-bundle.js:12493:51 <- webpack:///angular2/src/core/di/injector.ts:973:44
_getByKey@/Users/nsmith/projects/cohortable/spec-bundle.js:12439:42 <- webpack:///angular2/src/core/di/injector.ts:910:35
_getByDependency@/Users/nsmith/projects/cohortable/spec-bundle.js:12425:35 <- webpack:///angular2/src/core/di/injector.ts:892:28
_instantiate@/Users/nsmith/projects/cohortable/spec-bundle.js:12317:53 <- webpack:///angular2/src/core/di/injector.ts:781:46
_instantiateProvider@/Users/nsmith/projects/cohortable/spec-bundle.js:12308:38 <- webpack:///angular2/src/core/di/injector.ts:769:31
_new@/Users/nsmith/projects/cohortable/spec-bundle.js:12297:42 <- webpack:///angular2/src/core/di/injector.ts:758:37
getObjByKeyId@/Users/nsmith/projects/cohortable/spec-bundle.js:11907:55 <- webpack:///angular2/src/core/di/injector.ts:355:44
_getByKeyDefault@/Users/nsmith/projects/cohortable/spec-bundle.js:12493:51 <- webpack:///angular2/src/core/di/injector.ts:973:44
_getByKey@/Users/nsmith/projects/cohortable/spec-bundle.js:12439:42 <- webpack:///angular2/src/core/di/injector.ts:910:35
_getByDependency@/Users/nsmith/projects/cohortable/spec-bundle.js:12425:35 <- webpack:///angular2/src/core/di/injector.ts:892:28
_instantiate@/Users/nsmith/projects/cohortable/spec-bundle.js:12319:53 <- webpack:///angular2/src/core/di/injector.ts:783:46
_instantiateProvider@/Users/nsmith/projects/cohortable/spec-bundle.js:12308:38 <- webpack:///angular2/src/core/di/injector.ts:769:31
_new@/Users/nsmith/projects/cohortable/spec-bundle.js:12297:42 <- webpack:///angular2/src/core/di/injector.ts:758:37
getObjByKeyId@/Users/nsmith/projects/cohortable/spec-bundle.js:11907:55 <- webpack:///angular2/src/core/di/injector.ts:355:44
_getByKeyDefault@/Users/nsmith/projects/cohortable/spec-bundle.js:12493:51 <- webpack:///angular2/src/core/di/injector.ts:973:44
_getByKey@/Users/nsmith/projects/cohortable/spec-bundle.js:12439:42 <- webpack:///angular2/src/core/di/injector.ts:910:35
get@/Users/nsmith/projects/cohortable/spec-bundle.js:12116:31 <- webpack:///angular2/src/core/di/injector.ts:576:26
/Users/nsmith/projects/cohortable/spec-bundle.js:28333:36 <- webpack:///src/app/services/UserService.spec.ts:52:31
_instantiate@/Users/nsmith/projects/cohortable/spec-bundle.js:12413:87 <- webpack:///angular2/src/core/di/injector.ts:879:67
Expected undefined to be defined.
/Users/nsmith/projects/cohortable/spec-bundle.js:28336:41 <- webpack:///src/app/services/UserService.spec.ts:71:35
I have a basic UserService that takes a couple of objects in the constructor and if I want to test. I believe I have included everything that it needs for the test.
import { Store } from '@ngrx/store';
import { Router } from 'angular2/router';
import { Http } from 'angular2/http';
export const user: Reducer<any> = (state:any = initialState, action:Action) => {
...
}
@Injectable()
export class UserService {
constructor(public http:Http, private store:Store<any>, private router:Router) {}
}
export var USER_SERVICE_PROVIDERS: Array<any> = [
ROUTER_PROVIDERS,
Http,
provideStore({user}),
UserService,
];
-
import { UserService } from './UserService';
import { Injector, provide } from 'angular2/core';
describe('UserService', () => {
let injector:Injector;
let userService:UserService;
beforeEach(() => {
injector = Injector.resolveAndCreate([
provide(APP_BASE_HREF, { useValue: '/' }),
provide(ApplicationRef, {useClass: MockApplicationRef}),
provide(XHRBackend, {useClass: MockBackend}),
USER_SERVICE_PROVIDERS
});
userService = injector.get(UserService);
});
it('should be able to create a user service', () => {
expect(userService).toBeDefined();
});
});