Last active
May 17, 2019 13:59
Revisions
-
evertbouw revised this gist
Dec 20, 2018 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,10 +20,8 @@ export const setMessage = (message: string) => ({ payload: message }); export type AllActions = ReturnType<typeof ping | typeof pong | typeof setMessage>; export type MyReducer<S> = Reducer<S, AllActions>; export const messageReducer: MyReducer<string> = (state = "Hello", action) => { -
evertbouw revised this gist
Dec 20, 2018 . 1 changed file with 21 additions and 31 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,41 +3,31 @@ import { ActionsObservable, Epic, StateObservable } from "redux-observable"; import { TestScheduler } from "rxjs/testing"; const assertDeepEquals = (actual: any, expected: any) => { expect(actual).toEqual(expected); }; export const marbleTest = <T extends Action, O extends T = T, S = void, D = any>({ epic, actions, states = "", expected, values, dependencies, }: { epic: Epic<T, O, S, D>; actions: string; states?: string; expected: string; values: { [marble: string]: T | O | S }; dependencies?: D; }) => { const testScheduler = new TestScheduler(assertDeepEquals); testScheduler.run(({ hot, expectObservable }) => { const state$ = new StateObservable<S>(hot<S>(states, <{ [marble: string]: S }>values), <S>values.s); const action$ = new ActionsObservable<T>(hot<T>(actions, <{ [marble: string]: T }>values)); const output$ = epic(action$, state$, <D>dependencies); expectObservable(output$).toBe(expected, values); }); }; -
evertbouw revised this gist
Dec 20, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -31,8 +31,8 @@ export const marbleTest = < testScheduler.run(({ hot, expectObservable }) => { const state$ = new StateObservable( hot<S>(states, <Record<string, S>>values), <S>values.s // use s as the initial state ); const action$ = new ActionsObservable( hot<T>(actions, <Record<string, T>>values) ); -
evertbouw revised this gist
Dec 20, 2018 . 1 changed file with 16 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,26 +6,36 @@ const assertDeepEquals = (actual: any, expected: any) => { expect(actual).toEqual(expected); }; export const marbleTest = < T extends Action, O extends T = T, S = void, D = any >({ epic, actions, states = "", expected, values, dependencies }: { epic: Epic<T, O, S, D | undefined>; actions: string; states?: string; expected: string; values: Record<string, T | O | S>; dependencies?: D; }) => { const testScheduler = new TestScheduler(assertDeepEquals); testScheduler.run(({ hot, expectObservable }) => { const state$ = new StateObservable( hot<S>(states, <Record<string, S>>values), <S>values.s ); // use s as the initial state const action$ = new ActionsObservable( hot<T>(actions, <Record<string, T>>values) ); const output$ = epic(action$, state$, dependencies); expectObservable(output$).toBe(expected, values); -
evertbouw revised this gist
Dec 20, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export const marbleTest = <T extends Action, O extends T = T, S = void, D = any> actions: string; states?: string; expected: string; values: Record<string, T | O | S>, dependencies?: D; }) => { const testScheduler = new TestScheduler(assertDeepEquals); -
evertbouw revised this gist
Dec 20, 2018 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -18,16 +18,14 @@ export const marbleTest = <T extends Action, O extends T = T, S = void, D = any> actions: string; states?: string; expected: string; values: <Record<string, T | O | S>>, dependencies?: D; }) => { const testScheduler = new TestScheduler(assertDeepEquals); testScheduler.run(({ hot, expectObservable }) => { const state$ = new StateObservable(hot<S>(states, <Record<string, S>>values), <S>values.s); // use s as the initial state const action$ = new ActionsObservable(hot<T>(actions, <Record<string, T>>values)); const output$ = epic(action$, state$, dependencies); expectObservable(output$).toBe(expected, values); -
evertbouw revised this gist
Oct 31, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ import { marbleTest } from "./epicMarbleTest"; import { rootReducer, pingEpic, ping, pong, setMessage } from "./reducer"; test("ping epic", () => { -
evertbouw revised this gist
Jun 12, 2018 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ export const marbleTest = <T extends Action, O extends T = T, S = void, D = any> const testScheduler = new TestScheduler(assertDeepEquals); testScheduler.run(({ hot, expectObservable }) => { const state$ = new StateObservable(hot<S>(states, values), values.s); // use s as the initial state const action$ = new ActionsObservable(hot<T>(actions, values)); const output$ = epic(action$, state$, dependencies); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ test("ping epic", () => { expected: "5s 1 -- 2", values: { a: ping(), s, // s is used as the initial state, doesn't need to go in the marble t, 1: pong(s.message), 2: pong(t.message) -
evertbouw revised this gist
Jun 12, 2018 . 5 changed files with 61 additions and 60 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +0,0 @@ This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +0,0 @@ This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +0,0 @@ This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,21 @@ import { marbleTest } from "../../src/testHelper"; import { rootReducer, pingEpic, ping, pong, setMessage } from "./reducer"; test("ping epic", () => { const s = rootReducer(undefined, { type: "" }); const t = rootReducer(undefined, setMessage("world")); marbleTest({ epic: pingEpic, actions: "a -- a", states: " -- t", expected: "5s 1 -- 2", values: { a: ping(), s, t, 1: pong(s.message), 2: pong(t.message) } }); }); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,55 @@ import { combineReducers, Reducer } from "redux"; import { Epic, ofType } from "redux-observable"; import { mergeMap, take, map, delay } from "rxjs/operators"; export const PING: "PING" = "PING"; export const PONG: "PONG" = "PONG"; export const SET_MESSAGE: "SET_MESSAGE" = "SET_MESSAGE"; export const ping = () => ({ type: PING }); export const pong = (message: string) => ({ type: PONG, payload: message }); export const setMessage = (message: string) => ({ type: SET_MESSAGE, payload: message }); export type AllActions = | ReturnType<typeof ping> | ReturnType<typeof pong> | ReturnType<typeof setMessage>; export type MyReducer<S> = Reducer<S, AllActions>; export const messageReducer: MyReducer<string> = (state = "Hello", action) => { if (action.type === SET_MESSAGE) { return action.payload; } return state; }; export const rootReducer = combineReducers({ message: messageReducer }); export type MyState = ReturnType<typeof rootReducer>; export type MyEpic<O extends AllActions> = Epic<AllActions, O, MyState>; export const pingEpic: MyEpic<ReturnType<typeof pong>> = (action$, state$) => action$.pipe( ofType(PING), mergeMap(() => state$.pipe( take(1), map(state => state.message), delay(5000), map(pong) ) ) ); -
evertbouw revised this gist
Jun 12, 2018 . 5 changed files with 54 additions and 50 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ export const PING: "PING" = "PING"; export const PONG: "PONG" = "PONG"; export const SET_MESSAGE: "SET_MESSAGE" = "SET_MESSAGE"; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ import { PING, PONG, SET_MESSAGE } from "./actionTypes"; export const ping = () => ({ type: PING }); export const pong = (message: string) => ({ type: PONG, payload: message }); export const setMessage = (message: string) => ({ type: SET_MESSAGE, payload: message, }); export type AllActions = ReturnType<typeof ping> | ReturnType<typeof pong> | ReturnType<typeof setMessage>; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,50 +0,0 @@ This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import { Epic, ofType } from "redux-observable"; import { mergeMap, take, map, delay } from "rxjs/operators"; import { MyState } from "./reducer"; export type MyEpic<O extends AllActions> = Epic<AllActions, O, MyState>; export const pingEpic: MyEpic<ReturnType<typeof pong>> = (action$, state$) => action$.pipe( ofType(PING), mergeMap(() => state$.pipe( take(1), map(state => state.message), delay(5000), map(pong), )), ); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ import { combineReducers, Reducer } from "redux"; import { SET_MESSAGE } from "./actionTypes"; export type MyReducer<S> = Reducer<S, AllActions>; export const messageReducer: MyReducer<string> = (state = "Hello", action) => { if (action.type === SET_MESSAGE) { return action.payload; } return state; }; export const rootReducer = combineReducers({ message: messageReducer, }); export type MyState = ReturnType<typeof rootReducer>; -
evertbouw revised this gist
Jun 11, 2018 . 4 changed files with 67 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ import { combineReducers, Reducer } from "redux"; import { Epic, ofType } from "redux-observable"; import { mergeMap, take, map, delay } from "rxjs/operators"; export const PING: "PING" = "PING"; export const PONG: "PONG" = "PONG"; export const SET_MESSAGE: "SET_MESSAGE" = "SET_MESSAGE"; export const ping = () => ({ type: PING }); export const pong = (message: string) => ({ type: PONG, payload: message }); export const setMessage = (message: string) => ({ type: SET_MESSAGE, payload: message, }); export type AllActions = ReturnType<typeof ping> | ReturnType<typeof pong> | ReturnType<typeof setMessage>; export type MyReducer<S> = Reducer<S, AllActions>; export const messageReducer: MyReducer<string> = (state = "Hello", action) => { if (action.type === SET_MESSAGE) { return action.payload; } return state; }; export const rootReducer = combineReducers({ message: messageReducer, }); export type MyState = ReturnType<typeof rootReducer>; export type MyEpic<O extends AllActions> = Epic<AllActions, O, MyState>; export const pingEpic: MyEpic<ReturnType<typeof pong>> = (action$, state$) => action$.pipe( ofType(PING), mergeMap(() => state$.pipe( take(1), map(state => state.message), delay(5000), map(pong), )), ); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,20 @@ import { Action } from "redux"; import { ActionsObservable, Epic, StateObservable } from "redux-observable"; import { TestScheduler } from "rxjs/testing"; const assertDeepEquals = (actual: any, expected: any) => { expect(actual).toEqual(expected); }; export const marbleTest = <T extends Action, O extends T = T, S = void, D = any>({ epic, actions, states = "", expected, values, dependencies, }: { epic: Epic<T, O, S, D>; actions: string; states?: string; expected: string; @@ -26,9 +26,7 @@ export const marbleTest = <T extends AnyAction, S, D = any, O extends T = T>({ const testScheduler = new TestScheduler(assertDeepEquals); testScheduler.run(({ hot, expectObservable }) => { const state$ = new StateObservable(hot<S>(states, values), values.s); const action$ = new ActionsObservable(hot<T>(actions, values)); const output$ = epic(action$, state$, dependencies); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,21 @@ import { marbleTest } from "./epicMarbleTest"; import { rootReducer, pingEpic, ping, pong, setMessage } from "./duck"; const initialState = rootReducer(undefined, undefined); const newMessage = "world"; test("ping epic", () => { marbleTest({ epic: pingEpic, actions: "a -- a", states: " -- t", expected: "5s 1 -- 2", values: { a: ping(), s: initialState, t: rootReducer(initialState, setMessage(newMessage)), 1: pong(initialState.message), 2: pong(newMessage), }, }); }); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +0,0 @@ -
evertbouw revised this gist
May 31, 2018 . 3 changed files with 22 additions and 33 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,33 +6,32 @@ const assertDeepEquals = (actual: any, expected: any) => { expect(actual).toEqual(expected); }; export const marbleTest = <T extends AnyAction, S, D = any, O extends T = T>({ epic, actions, states, expected, values, dependencies, }: { epic: Epic<T, S, D, O>; actions: string; states?: string; expected: string; values: { [marble: string]: T | D | S }, dependencies?: D; }) => { const testScheduler = new TestScheduler(assertDeepEquals); testScheduler.run(({ hot, expectObservable }) => { // Second arg for StateObservable should be a store, but is only used for dispatch. // Since that is deprecated I don't want to support it in here const state$ = states && new StateObservable(hot<S>(states, values), undefined); const action$ = new ActionsObservable(hot<T>(actions, values)); const output$ = epic(action$, state$, dependencies); expectObservable(output$).toBe(expected, values); }); }; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,25 +4,15 @@ import { pingEpic } from "./pingEpic"; test("ping epic", () => { marbleTest({ epic: pingEpic, actions: "a -- a", states: "s -- t", expected: "5s z -- y", values: { a: { type: "ping" }, s: "Hello", t: "world", z: { type: "pong", payload: "Hello" }, y: { type: "pong", payload: "world" }, }, }); }); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,6 @@ export const pingEpic: Epic<AnyAction, string> = (action$, state$) => action$.pipe( ofType("ping"), withLatestFrom(state$), delay(5000), map(([, state]) => ({ type: "pong", payload: state })) ); -
evertbouw revised this gist
May 25, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export const marbleTest = <T extends AnyAction, S, D = any, O extends T = T>({ expected, dependencies }: { epic: Epic<T, O, S, D>; actions: MarblesAndValues<T>; states?: MarblesAndValues<S>; expected: MarblesAndValues<O>; -
evertbouw revised this gist
May 8, 2018 . No changes.There are no files selected for viewing
-
evertbouw revised this gist
May 8, 2018 . 4 changed files with 53 additions and 44 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,34 +6,33 @@ const assertDeepEquals = (actual: any, expected: any) => { expect(actual).toEqual(expected); }; export interface MarblesAndValues<V> { marbles: string; values: { [marble: string]: V }; } export const marbleTest = <T extends AnyAction, S, D = any, O extends T = T>({ epic, actions, states, expected, dependencies }: { epic: Epic<T, S, D, O>; actions: MarblesAndValues<T>; states?: MarblesAndValues<S>; expected: MarblesAndValues<O>; dependencies?: D; }) => { const testScheduler = new TestScheduler(assertDeepEquals); testScheduler.run(({ hot, expectObservable }) => { // Second arg for StateObservable should be a store, but is only used for dispatch. // Since that is deprecated I don't want to support it in here const state$ = states && new StateObservable(hot<S>(states.marbles, states.values), undefined); const action$ = new ActionsObservable(hot<T>(actions.marbles, actions.values)); const output$ = epic(action$, state$, dependencies); expectObservable(output$).toBe(expected.marbles, expected.values); }); }; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import { marbleTest } from "./helper"; import { pingEpic } from "./pingEpic"; test("ping epic", () => { marbleTest({ epic: pingEpic, actions: { marbles: " a -- a ", values: { a: { type: "ping" }, }, }, states: { marbles: " a -- b ", states: { a: "Hello", b: "world" }, }, expected: { marbles: " 5ms a -- b ", values: { a: { type: "pong", payload: "Hello" }, b: { type: "pong", payload: "world" }, }, } }); }); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ import { ofType, Epic } from "redux-observable"; import { delay, map, withLatestFrom } from "rxjs/operators"; import { AnyAction } from "redux"; export const pingEpic: Epic<AnyAction, string> = (action$, state$) => action$.pipe( ofType("ping"), withLatestFrom(state$), delay(5), map(([, state]) => ({ type: "pong", payload: state })) ); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,29 +0,0 @@ -
evertbouw revised this gist
May 2, 2018 . 2 changed files with 38 additions and 35 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,41 +1,39 @@ import { AnyAction } from "redux"; import { ActionsObservable, Epic, StateObservable } from "redux-observable"; import { TestScheduler } from "rxjs/testing"; const assertDeepEquals = (actual: any, expected: any) => { expect(actual).toEqual(expected); }; export const marbleTest = <T extends AnyAction, S, D = any, O extends T = T>({ epic, inputActions, inputMarble, stateMarble, states, expectedActions, expectedMarble, dependencies }: { epic: Epic<T, S, D, O>; inputActions: { [letter: string]: T }; inputMarble: string; stateMarble?: string; states?: { [letter: string]: S } expectedActions: { [letter: string]: O }; expectedMarble: string; dependencies?: D; }) => { const testScheduler = new TestScheduler(assertDeepEquals); testScheduler.run(({ hot, expectObservable }) => { // Second arg for StateObservable should be a store, but is only used for dispatch. // Since that is deprecated I don't want to support it in here const state$ = (stateMarble && states) ? new StateObservable(hot<S>(stateMarble, states), undefined as any) : (undefined as any); const action$ = new ActionsObservable(hot<T>(inputMarble, inputActions)); const output$ = epic(action$, state$, dependencies as any); expectObservable(output$).toBe(expectedMarble, expectedActions); }); }; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,29 @@ import { ofType } from "redux-observable"; import { delay, map, withLatestFrom } from "rxjs/operators"; import { marbleTest } from "./helper"; test("ping epic", () => { marbleTest({ epic: (action$, state$) => action$.pipe( ofType("ping"), withLatestFrom(state$), delay(5), map(([, state]) => ({ type: "pong", payload: state })), ), inputMarble: " a -- a ", inputActions: { a: { type: "ping" }, }, stateMarble: " a -- b ", states: { a: "Hello", b: "world" }, expectedMarble: " 5ms a -- b ", expectedActions: { a: { type: "pong", payload: "Hello" }, b: { type: "pong", payload: "world" }, }, }); }); -
evertbouw revised this gist
Apr 25, 2018 . 2 changed files with 25 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -38,4 +38,4 @@ export const marbleTest = <T extends AnyAction, S, D = any, O extends T = T>({ expectObservable(output$).toBe(expectedMarble, expectedActions); }); }; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ import { ofType } from "redux-observable"; import { delay, map, withLatestFrom } from "rxjs/operators"; import { marbleTest } from "./epicMarbleTest"; it("should do stuff", () => { marbleTest({ epic: (action$, state$) => action$.pipe( ofType("ping"), delay(5), withLatestFrom(state$), map(([, state]) => ({ type: "pong", payload: state })), ), inputMarble: "---a--------", inputActions: { a: { type: "ping" }, }, expectedMarble: "--------a---", expectedActions: { a: { type: "pong", payload: "Hello world" }, }, state: "Hello world", }); }); -
evertbouw revised this gist
Apr 25, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,6 @@ const assertDeepEquals = (actual: any, expected: any) => { expect(actual).toEqual(expected); }; export const marbleTest = <T extends AnyAction, S, D = any, O extends T = T>({ epic, inputActions, @@ -32,6 +30,8 @@ export const marbleTest = <T extends AnyAction, S, D = any, O extends T = T>({ }) => { stateInput$.next(state); const testScheduler = new TestScheduler(assertDeepEquals); testScheduler.run(({ hot, expectObservable }) => { const action$ = new ActionsObservable(hot<T>(inputMarble, inputActions)); const output$ = epic(action$, state$, dependencies); -
evertbouw created this gist
Apr 25, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ import { AnyAction } from "redux"; import { ActionsObservable, Epic, StateObservable } from "redux-observable"; import { Subject } from "rxjs"; import { TestScheduler } from "rxjs/testing"; const stateInput$ = new Subject(); const state$ = new StateObservable<any>(stateInput$, undefined); const assertDeepEquals = (actual: any, expected: any) => { expect(actual).toEqual(expected); }; const testScheduler = new TestScheduler(assertDeepEquals); export const marbleTest = <T extends AnyAction, S, D = any, O extends T = T>({ epic, inputActions, inputMarble, expectedActions, expectedMarble, state = {}, dependencies, }: { epic: Epic<T, S, D, O>; inputActions: { [letter: string]: T }; inputMarble: string; expectedActions: { [letter: string]: O }; expectedMarble: string; state?: S; dependencies?: D; }) => { stateInput$.next(state); testScheduler.run(({ hot, expectObservable }) => { const action$ = new ActionsObservable(hot<T>(inputMarble, inputActions)); const output$ = epic(action$, state$, dependencies); expectObservable(output$).toBe(expectedMarble, expectedActions); }); };