Skip to content

Commit

Permalink
WIP: Refine test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Wang Zhongliang committed Mar 1, 2018
1 parent 4eb7404 commit 196df61
Show file tree
Hide file tree
Showing 7 changed files with 2,836 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
14 changes: 5 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { Middleware, Action, AnyAction } from "redux";

interface ThunkDispatch<S, E, A extends Action> {
<T extends A>(action: T): T;
<R>(asyncAction: ThunkAction<R, S, E, A>): R;
}

export type ThunkAction<R, S, E, A extends Action> = (
dispatch: ThunkDispatch<S, E, A>,
getState: () => S,
extraArgument: E
) => R;

interface ThunkDispatch<S, E, A extends Action> {
<T extends A>(action: T): T;
}

interface ThunkDispatch<S, E, A extends Action> {
<R>(asyncAction: ThunkAction<R, S, E, A>): R;
}

type ThunkMiddleware<E, S = {}, A extends Action = AnyAction> = Middleware<ThunkDispatch<S, E, A>, S, ThunkDispatch<S, E, A>>;
type ThunkMiddleware<E> = Middleware<ThunkDispatch<S, E, A>, S, ThunkDispatch<S, E, A>>;

declare const thunk: ThunkMiddleware<undefined> & {
withExtraArgument<E>(extraArgument: E): ThunkMiddleware<E>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"mocha": "^2.2.5",
"redux": "4.0.0-beta.2",
"rimraf": "^2.5.2",
"typescript": "~2.4.0",
"typescript-definition-tester": "0.0.5",
"typescript": "~2.6.0",
"typings-tester": "^0.3.1",
"webpack": "^1.12.14"
}
}
10 changes: 3 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chai from 'chai';
import thunkMiddleware from '../src/index';
import * as tt from 'typescript-definition-tester';
import { check } from 'typings-tester';


describe('thunk middleware', () => {
Expand Down Expand Up @@ -97,12 +97,8 @@ describe('thunk middleware', () => {
describe('TypeScript definitions', function test() {
this.timeout(0);

it('should compile against index.d.ts', (done) => {
tt.compileDirectory(
__dirname,
fileName => fileName.match(/\.ts$/),
() => done()
);
it('should compile against index.d.ts', () => {
check([__dirname + '/typescript.ts'], __dirname + '/tsconfig.json');
});
});
});
8 changes: 8 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"strict": true
},
"files": [
"./*.ts"
]
}
6 changes: 5 additions & 1 deletion test/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ type State = {

type Actions = { type: 'FOO' };

function fakeReducer(state: State, action: Actions): State {
const initialState: State = {
foo: 'foo'
};

function fakeReducer(state: State = initialState, action: Actions): State {
return state;
}

Expand Down
Loading

0 comments on commit 196df61

Please sign in to comment.