Skip to content

Commit ef90265

Browse files
committed
migrated to using jest tesing harness
1 parent d37636d commit ef90265

File tree

7 files changed

+1352
-85
lines changed

7 files changed

+1352
-85
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ src/**/*.map
2929
node_modules
3030
jspm_packages
3131

32+
# Test snapshots
33+
__snapshots__
34+
3235
# Build directory
3336
dist
3437
temp

jest.config.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"automock": false,
3+
"moduleFileExtensions": [
4+
"ts",
5+
"tsx",
6+
"js"
7+
],
8+
"unmockedModulePathPatterns": [
9+
"<rootDir>/node_modules/react",
10+
"<rootDir>/node_modules/react-redux",
11+
"<rootDir>/node_modules/react-dom",
12+
"<rootDir>/node_modules/react-addons-test-utils",
13+
"<rootDir>/node_modules/fbjs"
14+
],
15+
"transform": {
16+
"^.+\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
17+
},
18+
"testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js",
19+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
20+
"notify": false,
21+
"verbose": true,
22+
"globals": {
23+
"window": {},
24+
"__TS_CONFIG__": "<rootDir>/src/tsconfig.json"
25+
}
26+
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
"lint": "tslint 'src/**/*.ts[x]'",
2828
"tsc": "tsc -p src",
2929
"tsc:watch": "tsc -p src -w",
30-
"test": "echo 'migrating to jest'",
30+
"test": "jest --config ./jest.config.json",
31+
"test:update": "jest -u --config ./jest.config.json",
3132
"regenerator": "node scripts/regenerator.js",
3233
"build:regenerator": "npm run build:app && npm run regenerator"
3334
},
3435
"devDependencies": {
3536
"@types/classnames": "^0.0.32",
37+
"@types/jest": "^16.0.1",
3638
"@types/react": "^0.14.43",
3739
"@types/react-dom": "^0.14.11",
3840
"@types/react-redux": "^4.4.32",
@@ -43,11 +45,13 @@
4345
"@types/systemjs": "^0.19.32",
4446
"@types/whatwg-fetch": "^0.0.32",
4547
"husky": "^0.11.8",
48+
"jest": "^17.0.3",
4649
"jspm": "^0.17.0-beta.32",
4750
"jspm-hmr": "^0.5.0",
4851
"regenerator": "^0.9.5",
4952
"shelljs": "^0.7.5",
5053
"shx": "^0.2.1",
54+
"ts-jest": "^17.0.3",
5155
"tslint": "^4.0.2",
5256
"typescript": "^2.1.4"
5357
},

src/services/local-storage/app-store.spec.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/store/currency-rates-reducer.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createAction, handleActions, Action } from 'redux-actions';
1+
import { handleActions, Action } from 'redux-actions';
22
import * as Immutable from 'seamless-immutable';
33

44
const RESPONSE_MOCK: IFixerServiceResponse = {
@@ -13,9 +13,15 @@ const LOAD_CURRENCY_RATES_SUCCESS = 'currencyRates/LOAD_CURRENCY_RATES_SUCCESS';
1313
const LOAD_CURRENCY_RATES_ERROR = 'currencyRates/LOAD_CURRENCY_RATES_ERROR';
1414

1515
// Action Creators
16-
export const loadCurrencyRates = createAction<void>(LOAD_CURRENCY_RATES);
17-
export const loadCurrencyRatesSuccess = createAction<IFixerServiceResponse>(LOAD_CURRENCY_RATES_SUCCESS);
18-
export const loadCurrencyRatesError = createAction<string>(LOAD_CURRENCY_RATES_ERROR);
16+
export const loadCurrencyRates = () => ({ type: LOAD_CURRENCY_RATES });
17+
export const loadCurrencyRatesSuccess = (payload: any) => ({
18+
type: LOAD_CURRENCY_RATES_SUCCESS,
19+
payload: payload,
20+
});
21+
export const loadCurrencyRatesError = (payload: any) => ({
22+
type: LOAD_CURRENCY_RATES_ERROR,
23+
payload: payload,
24+
});
1925

2026

2127
// Reducer

src/store/specs/currency-rates-reducer.spec.tsx renamed to src/store/spec/currency-rates-reducer.spec.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
import * as test from 'blue-tape';
1+
// MOCKING
2+
jest.mock('redux-actions', () => {
3+
return {
4+
handleActions: () => ({}),
5+
};
6+
}, { virtual: true });
7+
jest.mock('seamless-immutable', () => {
8+
return {
9+
from: () => ({}),
10+
};
11+
}, { virtual: true });
12+
213
import * as currencyRatesActions from '../currency-rates-reducer';
314

415
// testing action creators
516

6-
test('testing action creator currencyRatesFetchSuccess', function (t) {
17+
test('testing action creator currencyRatesFetchSuccess', () => {
718
// arrange
819
// tslint:disable
920
const results = {
@@ -23,12 +34,10 @@ test('testing action creator currencyRatesFetchSuccess', function (t) {
2334
};
2435

2536
// assert
26-
t.deepEqual(actual, expected, 'should deep equal expected action');
27-
t.end();
28-
37+
expect(actual).toEqual(expected);
2938
});
3039

31-
test('testing action creator currencyRatesFetchError', function (t) {
40+
test('testing action creator currencyRatesFetchError', () => {
3241
// arrange
3342
const errorMessage = 'Error Message';
3443

@@ -40,8 +49,7 @@ test('testing action creator currencyRatesFetchError', function (t) {
4049
};
4150

4251
// assert
43-
t.deepEqual(actual, expected, 'should deep equal expected action');
44-
t.end();
52+
expect(actual).toEqual(expected);
4553
});
4654

4755
// testing reducer

0 commit comments

Comments
 (0)