diff --git a/test/applyMiddleware.spec.js b/test/applyMiddleware.spec.ts similarity index 78% rename from test/applyMiddleware.spec.js rename to test/applyMiddleware.spec.ts index f681dee0ee..69a4e5766b 100644 --- a/test/applyMiddleware.spec.js +++ b/test/applyMiddleware.spec.ts @@ -1,4 +1,11 @@ -import { createStore, applyMiddleware } from '../' +import { + createStore, + applyMiddleware, + Middleware, + Dispatch, + AnyAction, + Action +} from '..' import * as reducers from './helpers/reducers' import { addTodo, addTodoAsync, addTodoIfEmpty } from './helpers/actionCreators' import { thunk } from './helpers/middleware' @@ -51,7 +58,11 @@ describe('applyMiddleware', () => { const spy = jest.fn() const store = applyMiddleware(test(spy), thunk)(createStore)(reducers.todos) - return store.dispatch(addTodoAsync('Use Redux')).then(() => { + // the typing for redux-thunk is super complex, so we will use an as unknown hack + const dispatchedValue = (store.dispatch( + addTodoAsync('Use Redux') + ) as unknown) as Promise + return dispatchedValue.then(() => { expect(spy.mock.calls.length).toEqual(2) }) }) @@ -87,7 +98,11 @@ describe('applyMiddleware', () => { } ]) - store.dispatch(addTodoAsync('Maybe')).then(() => { + // the typing for redux-thunk is super complex, so we will use an "as unknown" hack + const dispatchedValue = (store.dispatch( + addTodoAsync('Maybe') + ) as unknown) as Promise + dispatchedValue.then(() => { expect(store.getState()).toEqual([ { id: 1, @@ -110,8 +125,16 @@ describe('applyMiddleware', () => { const spy = jest.fn() const testCallArgs = ['test'] - function multiArgMiddleware() { - return next => (action, callArgs) => { + interface MultiDispatch { + (action: T, extraArg?: string[]): T + } + + const multiArgMiddleware: Middleware< + MultiDispatch, + any, + MultiDispatch + > = _store => { + return next => (action, callArgs?: any) => { if (Array.isArray(callArgs)) { return action(...callArgs) }