Jakub Szafraniec
let result; service.getSomething$().subscribe((value) => { result = value; });
it('should ....', () => {
tick(100); expect(result).toEqual(A);
tick(300); expect(result).toEqual(B);
tick(500); expect(result).toEqual(C);
350?
START -> 100ms A 300ms B 500ms C -> END
fakeAsync(
it('generate the stream correctly', () => { testScheduler.run(helpers => { }); });
const e1 = cold(' -a--b--c---|'); const subs = ' ^----------!'; const expected = '-a-----c---|';
const { cold, expectObservable, expectSubscriptions } = helpers;
expectSubscriptions(e1.subscriptions) .toBe(subs);
expectObservable(e1.pipe(/without b/)) .toBe(expected);
import {TestScheduler} from 'rxjs/testing'; const testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected); });
cold('--a--b--c', { a: 'foo', b: 123, c: { x: { y: 3; }, z: false } })
cold()
hot()
expectObservable()
expectSubscriptions()
flush()
cold(' a---b 100ms (ab) 100ms c---#')
expect(/c/).toBe('----- 100ms - 100ms c---#')
@szafraniec_kuba
https://rxjs.dev/guide/testing/marble-testing
https://github.com/kszafraniec/rxjs-marbles-demo