mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
[redux-test-utils] typing for version 0.2
Add type definitions for redux-test-utils
This commit is contained in:
23
types/redux-test-utils/index.d.ts
vendored
Normal file
23
types/redux-test-utils/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
6
types/redux-test-utils/package.json
Normal file
6
types/redux-test-utils/package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
37
types/redux-test-utils/redux-test-utils-tests.ts
Normal file
37
types/redux-test-utils/redux-test-utils-tests.ts
Normal 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;
|
||||
}
|
||||
23
types/redux-test-utils/tsconfig.json
Normal file
23
types/redux-test-utils/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/redux-test-utils/tslint.json
Normal file
1
types/redux-test-utils/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user