Skip to content

Instantly share code, notes, and snippets.

@kylewhitaker
Created September 9, 2017 00:20
Show Gist options
  • Save kylewhitaker/86dda45793230e33a2abfb8d7d05e236 to your computer and use it in GitHub Desktop.
Save kylewhitaker/86dda45793230e33a2abfb8d7d05e236 to your computer and use it in GitHub Desktop.
Unit testing an Observable with Jasmine's done() function
import { SomeComponent } from './some.component';
describe('SomeComponent:', () => {
let component: SomeComponent;
beforeEach(() => {
component = new SomeComponent();
});
describe('returnSomeObservable', () => {
it('should return an observable that emits a \'test\' string value', (done) => {
component.returnSomeObservable().subscribe((value) => {
expect(value).toEqual('test');
done();
});
});
});
});
import { Observable } from 'rxjs';
export class SomeComponent {
returnSomeObservable(): Observable<string> {
return Observable.of('test');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment