[redux-test-utils] typing for version 0.2

Add type definitions for redux-test-utils
This commit is contained in:
Huw Martin
2018-03-10 16:48:33 +00:00
parent d44c90df2d
commit 937cfc12f1
5 changed files with 90 additions and 0 deletions

23
types/redux-test-utils/index.d.ts vendored Normal file
View File

@@ -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 <https://github.com/huwmartin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { AnyAction, Store, Dispatch } from 'redux';
export function createMockStore(
state?: any
): mockStore<any>;
export function createMockDispatch(): mockDispatch<any>;
export interface mockStore<S> extends Store<S>, mockDispatch<S> {}
export interface mockDispatch<S> {
dispatch: Dispatch<S>;
getActions: () => AnyAction[];
getAction: (type: any) => AnyAction | undefined;
isActionTypeDispatched: (type: any) => boolean;
isActionDispatched: (action: AnyAction) => boolean;
}

View File

@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"redux": "^3.6.0"
}
}

View File

@@ -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;
}

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }