Angular 2 Unit Test for a promise
I normally use fakeAsync to test a subscribe returning an observable. But on this rare occasion, I need to do the same but for a promise. This is my attempt: //Service Stub: const testService = { testMethod: jasmine.createSpy('testMethod').and.callFake(() => new Promise(() => 'test')) }; it('test example',() => { // Arrange const response = 'test'; component.selected = undefined; // Act component['myMethod'](); //Assert expect(component.selected).toEqual(response); }); This is my actual code: private myMethod(): void { return this.testService.testMethod() .then((response: string) => { this.sel
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.