Skip to content

Instantly share code, notes, and snippets.

@vire vire/handler.spec.js
Created Jul 10, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.