Add definitions for redux-mock-store (#9328)

* Add definitions for redux-mock-store.

* Fix definitions of redux-mock-store and updated tests.

* Remove trailing empty line.
This commit is contained in:
Marian Palkus
2016-05-14 19:34:14 +02:00
committed by Masahiro Wakame
parent a9b1e55740
commit acdc2d397c
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
/// <reference path="./redux-mock-store.d.ts" />
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<any> = store.getActions();
store.clearActions();

24
redux-mock-store/redux-mock-store.d.ts vendored Normal file
View File

@@ -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 <https://github.com/MarianPalkus>, Cap3 <http://www.cap3.de>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path="../redux/redux.d.ts" />
declare module 'redux-mock-store' {
import * as Redux from 'redux'
function createMockStore<T>(middlewares?:Redux.Middleware[]):mockStore<T>
type mockStore<T> = (state?:T) => IStore<T>;
type IStore<T> = {
dispatch(action: any):any
getState():T
getActions():Object[]
clearActions():void
subscribe(listener: Function):Function
}
export default createMockStore
}