Created
September 11, 2017 15:24
-
-
Save kylewhitaker/8c701373de45a5ddfd0bad9454651fec to your computer and use it in GitHub Desktop.
Wrap your observable subscriptions inside a FakeAsync zone and make it Tick!
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
import { fakeAsync, tick } from '@angular/core/testing'; | |
import { Observable } from 'rxjs/Observable'; | |
import { SomeComponent } from './some.component'; | |
describe('SomeComponent:', () => { | |
let component: SomeComponent; | |
let mockDepThree: any; | |
beforeEach(() => { | |
mockDepThree = jasmine.createSpyObj('DepThree', ['capitalize']); | |
component = new SomeComponent(mockDepThree); | |
}); | |
describe('subscribeAndDoSomething', () => { | |
it('should call depThree.capitalize on the value emitted', fakeAsync(() => { | |
component.subscribeAndDoSomething(); | |
tick(); | |
expect(mockDepThree.capitalize).toHaveBeenCalledWith('jabroni'); | |
})); | |
}); | |
}); |
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
import { Observable } from 'rxjs'; | |
import { DepThree } from './dependencies'; | |
export class SomeComponent { | |
constructor(private depThree: DepThree) { } | |
subscribeAndDoSomething(): void { | |
Observable.of('jabroni').subscribe((value) => { | |
this.depThree.capitalize(value); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment