diff --git a/types/redux-test-utils/index.d.ts b/types/redux-test-utils/index.d.ts new file mode 100644 index 0000000000..2c5a36e441 --- /dev/null +++ b/types/redux-test-utils/index.d.ts @@ -0,0 +1,23 @@ +// Type definitions for redux-test-utils 0.2 +// Project: https://github.com/Knegusen/redux-test-utils#readme +// Definitions by: Huw Martin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { AnyAction, Store, Dispatch } from 'redux'; + +export function createMockStore( + state?: any +): mockStore; + +export function createMockDispatch(): mockDispatch; + +export interface mockStore extends Store, mockDispatch {} + +export interface mockDispatch { + dispatch: Dispatch; + getActions: () => AnyAction[]; + getAction: (type: any) => AnyAction | undefined; + isActionTypeDispatched: (type: any) => boolean; + isActionDispatched: (action: AnyAction) => boolean; +} diff --git a/types/redux-test-utils/package.json b/types/redux-test-utils/package.json new file mode 100644 index 0000000000..6d68bf2f9b --- /dev/null +++ b/types/redux-test-utils/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "redux": "^3.6.0" + } +} diff --git a/types/redux-test-utils/redux-test-utils-tests.ts b/types/redux-test-utils/redux-test-utils-tests.ts new file mode 100644 index 0000000000..9fc8df2c13 --- /dev/null +++ b/types/redux-test-utils/redux-test-utils-tests.ts @@ -0,0 +1,37 @@ +import * as chai from 'chai'; + +import { createMockStore, createMockDispatch } from 'redux-test-utils'; + +const expect = chai.expect; +const assert = chai.assert; + +function test_creatMockStore() { + const state = 'state'; + const store = createMockStore(state); + const action = { + type: 'type', + data: 'data' + }; + store.dispatch(action); + + expect(store.getAction(action.type)).to.equal(action); + expect(store.getActions()).to.equal([action]); + expect(store.isActionDispatched(action)).to.be.true; + expect(store.isActionTypeDispatched(action.type)).to.be.true; + expect(store.getState()).to.be(state); +} + +function test_createMockDispatch() { + const state = 'state'; + const dispatchMock = createMockDispatch(); + const action = { + type: 'type', + data: 'data', + }; + dispatchMock.dispatch(action); + + expect(dispatchMock.getAction(action.type)).to.equal(action); + expect(dispatchMock.getActions()).to.equal([action]); + expect(dispatchMock.isActionDispatched(action)).to.be.true; + expect(dispatchMock.isActionTypeDispatched(action.type)).to.be.true; +} diff --git a/types/redux-test-utils/tsconfig.json b/types/redux-test-utils/tsconfig.json new file mode 100644 index 0000000000..5b074d5fa2 --- /dev/null +++ b/types/redux-test-utils/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "redux-test-utils-tests.ts" + ] +} diff --git a/types/redux-test-utils/tslint.json b/types/redux-test-utils/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/redux-test-utils/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }