diff --git a/redux-mock-store/redux-mock-store-tests.ts b/redux-mock-store/redux-mock-store-tests.ts new file mode 100644 index 0000000000..1b0a53968b --- /dev/null +++ b/redux-mock-store/redux-mock-store-tests.ts @@ -0,0 +1,43 @@ +/// + +import configureStore from 'redux-mock-store'; + +// Redux store API tests +// The following test are taken from ../redux/redux-tests.ts +function counter(state: any, action: any) { + if (!state) { + state = 0; + } + switch (action.type) { + case 'INCREMENT': + return state + 1; + case 'DECREMENT': + return state - 1; + default: + return state; + } +} + +function loggingMiddleware() { + return (next: Redux.Dispatch) => (action: any) => { + console.log(action.type); + next(action); + }; +} + +const storeMock = configureStore([loggingMiddleware]); +const initialState = 0 +let store = storeMock(initialState); + + +store.subscribe(() => { + // ... +}); + +store.dispatch({ type: 'INCREMENT' }); + + +// Additional mock store API tests +var actions: Array = store.getActions(); + +store.clearActions(); \ No newline at end of file diff --git a/redux-mock-store/redux-mock-store.d.ts b/redux-mock-store/redux-mock-store.d.ts new file mode 100644 index 0000000000..770603826a --- /dev/null +++ b/redux-mock-store/redux-mock-store.d.ts @@ -0,0 +1,24 @@ +// Type definitions for Redux Mock Store v0.0.6 +// Project: https://github.com/arnaudbenard/redux-mock-store +// Definitions by: Marian Palkus , Cap3 +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module 'redux-mock-store' { + import * as Redux from 'redux' + + function createMockStore(middlewares?:Redux.Middleware[]):mockStore + + type mockStore = (state?:T) => IStore; + + type IStore = { + dispatch(action: any):any + getState():T + getActions():Object[] + clearActions():void + subscribe(listener: Function):Function + } + + export default createMockStore +} \ No newline at end of file