Skip to content

Instantly share code, notes, and snippets.

@veeramarni
Created April 20, 2019 12:00
Show Gist options
  • Save veeramarni/76ed05fe0f550b98db8dd0a8e20ac3c6 to your computer and use it in GitHub Desktop.
Save veeramarni/76ed05fe0f550b98db8dd0a8e20ac3c6 to your computer and use it in GitHub Desktop.
BasicMarbleTestRxJs
test('test rxjs marble', async () => {
const testScheduler = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected);
});
const fetchUserEpic = (action$, state$, { getJSON }) => action$.pipe(
ofType('FETCH_USER'),
mergeMap(action =>
getJSON(`https://api.github.com/users/${action.id}`).pipe(
map(response => ({ type: 'FETCH_USER_FULFILLED', response }))
)
)
);
testScheduler.run(({ hot, cold, expectObservable }) => {
const action$ = hot('-a', {
a: { type: 'FETCH_USER', id: '123' },
});
const state$ = null;
const dependencies = {
getJSON: url => cold('--a', {
a: { url },
}),
}
const output$ = fetchUserEpic(action$, state$, dependencies);
expectObservable(output$).toBe('---a', {
a: {
type: 'FETCH_USER_FULFILLED',
response: {
url: 'https://api.github.com/users/123',
},
},
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment