mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
export types of redux-mock-store (#10933)
Within a test you sometimes want to declare the store first and then assign it the result of mockStore(state) in a beforeEach(). For that we need to export IStore.
This commit is contained in:
committed by
Masahiro Wakame
parent
13322c67cc
commit
49d0ce6918
@@ -1,6 +1,6 @@
|
||||
/// <reference path="./redux-mock-store.d.ts" />
|
||||
|
||||
import configureStore from 'redux-mock-store';
|
||||
import configureStore, {IStore} from 'redux-mock-store';
|
||||
|
||||
// Redux store API tests
|
||||
// The following test are taken from ../redux/redux-tests.ts
|
||||
@@ -25,10 +25,11 @@ function loggingMiddleware() {
|
||||
};
|
||||
}
|
||||
|
||||
const storeMock = configureStore([loggingMiddleware]);
|
||||
const storeMock = configureStore<number>([loggingMiddleware]);
|
||||
const initialState = 0
|
||||
let store = storeMock(initialState);
|
||||
let store: IStore<number>;
|
||||
|
||||
store = storeMock(initialState);
|
||||
|
||||
store.subscribe(() => {
|
||||
// ...
|
||||
@@ -40,4 +41,4 @@ store.dispatch({ type: 'INCREMENT' });
|
||||
// Additional mock store API tests
|
||||
var actions: Array<any> = store.getActions();
|
||||
|
||||
store.clearActions();
|
||||
store.clearActions();
|
||||
|
||||
6
redux-mock-store/redux-mock-store.d.ts
vendored
6
redux-mock-store/redux-mock-store.d.ts
vendored
@@ -10,9 +10,9 @@ declare module 'redux-mock-store' {
|
||||
|
||||
function createMockStore<T>(middlewares?:Redux.Middleware[]):mockStore<T>
|
||||
|
||||
type mockStore<T> = (state?:T) => IStore<T>;
|
||||
export type mockStore<T> = (state?:T) => IStore<T>;
|
||||
|
||||
type IStore<T> = {
|
||||
export type IStore<T> = {
|
||||
dispatch(action: any):any
|
||||
getState():T
|
||||
getActions():Object[]
|
||||
@@ -21,4 +21,4 @@ declare module 'redux-mock-store' {
|
||||
}
|
||||
|
||||
export default createMockStore
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user