Skip to content

Instantly share code, notes, and snippets.

@vire
Created July 10, 2018 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vire/806158c18fe0f14637cc37d0514d3f08 to your computer and use it in GitHub Desktop.
Save vire/806158c18fe0f14637cc37d0514d3f08 to your computer and use it in GitHub Desktop.
import { marbles } from "rxjs-marbles/jest";
import { map, startWith, scan } from "rxjs/operators";
import { Subject, merge, of } from "rxjs";
describe("basic", () => {
it(
"should update state by calling the handler as expected",
marbles(m => {
const createHandler = () => {
const stream$ = new Subject();
return {
stream$,
handler: val => stream$.next(val)
};
};
const {
stream$: numberStream$,
handler: increment
} = createHandler();
const numberState$ = numberStream$.pipe(
map(value => state => {
return {
...state,
counter: value
};
})
);
const initialState = {
counter: 0
};
const source = numberState$.pipe(
startWith(initialState),
scan((state, fn) => fn(state))
);
// call the handler
increment(42);
const updatedState = { counter: 42 };
const expected$ = m.cold("i-u", {
i: initialState, // pases
u: updatedState // is not present
});
m.expect(source).toBeObservable(expected$);
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment