Created
July 10, 2018 20:49
-
-
Save vire/806158c18fe0f14637cc37d0514d3f08 to your computer and use it in GitHub Desktop.
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 { 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