I'm trying to create a spy object for my tests:
let spy: jasmine.SpyObj<GeneralService>;
Unfortunately, I'm getting this error when running ng test
:
Namespace 'jasmine' has no exported member 'SpyObj'
In addition, WebStorm marks SpyObj
as unresolved variable.
Here is devDependencies
from my package.json
:
"devDependencies": {
"@angular/cli": "1.7.3",
"@types/jasmine": "2.5.36",
"@types/node": "7.0.27",
"jasmine": "~2.4.1",
"jasmine-core": "~2.4.1",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.2",
"lodash": "4.16.2",
"ts-node": "1.3.0",
"tslint": "^3.15.1",
"typescript": "2.6.2"
}
UPDATE:
I refer to Angular testing docs: https://angular.io/guide/testing
let masterService: MasterService;
let valueServiceSpy: jasmine.SpyObj<ValueService>;
beforeEach(() => {
const spy = jasmine.createSpyObj('ValueService', ['getValue']);
TestBed.configureTestingModule({
// Provide both the service-to-test and its (spy) dependency
providers: [
MasterService,
{ provide: ValueService, useValue: spy }
]
});
// Inject both the service-to-test and its (spy) dependency
masterService = TestBed.get(MasterService);
valueServiceSpy = TestBed.get(ValueService);
});
I end up configure spy as any
:
let spy: any;