From 14273631aae1f8c3538bf8a222a4323acceb1ba6 Mon Sep 17 00:00:00 2001 From: rjz Date: Sat, 8 Apr 2017 15:16:05 -0700 Subject: [PATCH] Update tsc and fix spec type errors --- package.json | 25 ++++++++++++------- src/actions/__tests__/index_spec.ts | 6 +++-- src/actions/index.ts | 2 +- src/api.ts | 7 +++++- .../__snapshots__/counter_spec.tsx.snap | 22 +++++++++++++++- tsconfig.json | 1 + 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 6892941..ac49f71 100644 --- a/package.json +++ b/package.json @@ -20,30 +20,37 @@ "author": "RJ Zaworski (http://rjzaworski.com)", "license": "ISC", "dependencies": { - "react": "15.4.1", - "react-redux": "4.4.6", + "react": "15.4.2", + "react-redux": "5.0.3", "redux": "3.6.0", - "redux-thunk": "^2.2.0" + "redux-thunk": "2.2.0" }, "devDependencies": { - "@types/react": "0.14.55", - "@types/react-dom": "0.14.20", + "@types/jest": "19.2.2", + "@types/minimist": "1.2.0", + "@types/node": "7.0.12", + "@types/react": "15.0.21", + "@types/react-dom": "0.14.23", + "@types/react-redux": "4.4.38", + "@types/redux": "3.6.0", + "@types/semver": "5.3.31", + "@types/sinon": "2.1.2", "babel-core": "6.14.0", "babel-loader": "6.2.5", "babel-polyfill": "6.20.0", "babel-preset-es2015": "6.14.0", "coveralls": "2.11.15", "http-server": "0.9.0", - "jest": "17.0.3", - "jest-cli": "17.0.3", + "jest": "19.0.2", + "jest-cli": "19.0.2", "react-addons-test-utils": "15.4.1", "react-dom": "15.4.1", "sinon": "1.17.4", "source-map-loader": "0.1.5", - "ts-jest": "17.0.3", + "ts-jest": "19.0.7", "ts-loader": "0.8.2", "tslint": "3.14.0", - "typescript": "2.0.6", + "typescript": "2.3.0", "typings": "2.1.0", "webpack": "1.13.1", "webpack-fail-plugin": "1.0.5", diff --git a/src/actions/__tests__/index_spec.ts b/src/actions/__tests__/index_spec.ts index 41f2953..6354ad9 100644 --- a/src/actions/__tests__/index_spec.ts +++ b/src/actions/__tests__/index_spec.ts @@ -1,9 +1,11 @@ jest.mock('../../api') import { createStore } from 'redux' -import { api } from '../../api' +import * as apiExports from '../../api' import * as actions from '../index' +const api: jest.Mocked = apiExports.api as any + describe('actions', () => { const store = () => { const reducer = jest.fn() @@ -34,7 +36,7 @@ describe('actions', () => { }) it('sends an API request', () => { - actions.saveCount({ value: '14' })(jest.fn()) + actions.saveCount({ value: 14 })(jest.fn()) expect(api.save.mock.calls.length).toEqual(1) }) diff --git a/src/actions/index.ts b/src/actions/index.ts index 96c3913..07709cd 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -69,4 +69,4 @@ function apiActionGroupFactory(x: ApiActionGroup, go: apiFunc) } export const saveCount = apiActionGroupFactory(_saveCount, api.save) -export const loadCount = apiActionGroupFactory(_loadCount, api.load) +export const loadCount = () => apiActionGroupFactory(_loadCount, api.load)(null) diff --git a/src/api.ts b/src/api.ts index 3d0432f..067f881 100644 --- a/src/api.ts +++ b/src/api.ts @@ -18,7 +18,12 @@ const flakify = (f: () => T): Promise => }, 200 + Math.random() * 2000) ) -export const api = { +export type Api = { + save(x: { value: number }): Promise, + load(): (Promise<{ value: number }>), +} + +export const api: Api = { save: (counter: { value: number }): Promise => flakify(() => { localStorage.setItem('__counterValue', counter.value.toString()) return null diff --git a/src/components/__tests__/__snapshots__/counter_spec.tsx.snap b/src/components/__tests__/__snapshots__/counter_spec.tsx.snap index 3679ee2..deff78a 100644 --- a/src/components/__tests__/__snapshots__/counter_spec.tsx.snap +++ b/src/components/__tests__/__snapshots__/counter_spec.tsx.snap @@ -1,3 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + exports[`components/Counter renders 1`] = ` + } + storeSubscription={ + Subscription { + "listeners": Object { + "notify": [Function], + }, + "onStateChange": [Function], + "parentSub": undefined, + "store": Object { + "dispatch": [Function], + "getState": [Function], + "replaceReducer": [Function], + "subscribe": [Function], + Symbol(observable): [Function], + }, + "unsubscribe": null, + } + } +/> `; diff --git a/tsconfig.json b/tsconfig.json index 704bb7a..f124d66 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "outDir": "./dist/", "sourceMap": true, "noImplicitAny": true, + "lib": ["es6"], "module": "commonjs", "target": "es6", "jsx": "react"