Created
March 24, 2020 09:57
-
-
Save derdaani/45026f52b0249f4b9f555f16e12ba216 to your computer and use it in GitHub Desktop.
Jasmine mock getters, class variables, class functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Service Test', () => { | |
let service: SomeService; | |
let stubbedService: jasmine.SpyObj<StubbedService>; | |
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
providers: [ | |
{ | |
provide: StubbedService, | |
useValue: { | |
...jasmine.createSpyObj('stubbedService', ['serviceFunc1', 'serviceFunc2']), | |
classVariable: undefined, | |
classGetter: undefined, | |
} as jasmine.SpyObj<StubbedService>, | |
}, | |
], | |
}); | |
service = TestBed.get(SomeService); | |
stubbedService = TestBed.get(StubbedService); | |
}); | |
describe('now we have spies for all StubbedService properties', () => { | |
it('spy on all', () => { | |
stubbedServie.classVariable = 'some mocked stuff'; | |
stubbedService.classGetter = 'more mocked stuff'; | |
stubbedService.serviceFunc1.and.returnValue('mocked function return'); | |
stubbedService.serviceFunc2.and.returnValue(of('mocked function observale return')); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment