[redux-mock-store] Update types to be compatible with redux 4.0

This commit is contained in:
Chung N Ho
2018-06-21 11:26:12 -07:00
parent 248ceaecc0
commit e108a34718
8 changed files with 122 additions and 6 deletions
+14 -4
View File
@@ -1,4 +1,4 @@
// Type definitions for Redux Mock Store 0.0.1
// Type definitions for Redux Mock Store 1.0.0
// 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
@@ -6,13 +6,23 @@
import * as Redux from 'redux';
export interface MockStore<T> extends Redux.Store<T> {
export interface MockStore<S = any, A extends Redux.Action = Redux.AnyAction> extends Redux.Store<S, A> {
getActions(): any[];
clearActions(): void;
}
export type MockStoreCreator<T = {}> = (state?: T) => MockStore<T>;
export type MockStoreEnhanced<S = {}, DispatchExts = {}> = MockStore<S> & {dispatch: DispatchExts};
declare function createMockStore<T>(middlewares?: Redux.Middleware[]): MockStoreCreator<T>;
export type MockStoreCreator<S = {}, DispatchExts = {}> = (state?: S) => MockStoreEnhanced<S, DispatchExts>;
/**
* Create Mock Store returns a function that will create a mock store from a state
* with the same set of set of middleware applied.
*
* @param middlewares The list of middleware to be applied.
* @template S The type of state to be held by the store.
* @template DispatchExts The additional Dispatch signatures for the middlewares applied.
*/
declare function createMockStore<S, DispatchExts = {}>(middlewares?: Redux.Middleware[]): MockStoreCreator<S, DispatchExts>;
export default createMockStore;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"private": true,
"dependencies": {
"redux": "^3.6.0"
"redux": "^4.0.0"
}
}
@@ -18,7 +18,7 @@ function counter(state: any, action: any) {
}
function loggingMiddleware() {
return (next: Redux.Dispatch<any>) => (action: any) => {
return (next: Redux.Dispatch<Redux.AnyAction>) => (action: any) => {
console.log(action.type);
return next(action);
};
+18
View File
@@ -0,0 +1,18 @@
// Type definitions for Redux Mock Store 0.0.1
// 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
// TypeScript Version: 2.3
import * as Redux from 'redux';
export interface MockStore<T> extends Redux.Store<T> {
getActions(): any[];
clearActions(): void;
}
export type MockStoreCreator<T = {}> = (state?: T) => MockStore<T>;
declare function createMockStore<T>(middlewares?: Redux.Middleware[]): MockStoreCreator<T>;
export default createMockStore;
+6
View File
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"redux": "^3.6.0"
}
}
@@ -0,0 +1,45 @@
import * as Redux from 'redux';
import configureStore, { MockStore, MockStoreCreator } 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<any>) => (action: any) => {
console.log(action.type);
return next(action);
};
}
const mockStoreCreator: MockStoreCreator<number> = configureStore<number>([loggingMiddleware]);
const initialState = 0;
const store: MockStore<number> = mockStoreCreator(initialState);
store.subscribe(() => {
// ...
});
store.dispatch({ type: 'INCREMENT' });
// Additional mock store API tests
const actions: any[] = store.getActions();
store.clearActions();
// actions access without the need to cast
const actions2 = store.getActions();
actions2[10].payload.id;
+29
View File
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"types": [],
"paths": {
"redux-mock-store": [
"redux-mock-store/v0"
]
},
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"redux-mock-store-tests.ts"
]
}
+8
View File
@@ -0,0 +1,8 @@
{
"extends": "dtslint/dt.json",
"rules": {
// TODO
"dt-header": false,
"no-unnecessary-generics": false
}
}