Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Added sample "jest" tests for counter reducer #509 #1041

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions templates/ReactReduxSpa/ClientApp/store/Counter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'jest';
import { reducer } from './Counter';

describe('Coutner reducer', () => {
it('should handle initial state', () => {
expect(reducer(undefined, {} as any)).toEqual({ count: 0 });
});

it('should handle INCREMENT_COUNT', () => {
expect(reducer(
{ count: 0 },
{ type: 'INCREMENT_COUNT' }))
.toEqual({ count: 1 });
});

it('should handle DECREMENT_COUNT', () => {
expect(reducer(
{ count: 1 },
{ type: 'DECREMENT_COUNT' }))
.toEqual({ count: 0 });
});
});
18 changes: 18 additions & 0 deletions templates/ReactReduxSpa/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
{
"name": "WebApplicationBasic",
"version": "0.0.0",
"scripts": {
"test": "jest"
},
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
]
},
"dependencies": {
"@types/history": "4.5.1",
"@types/jest": "20.0.0",
"@types/react": "15.0.24",
"@types/react-dom": "15.5.0",
"@types/react-redux": "4.4.40",
Expand All @@ -21,6 +37,7 @@
"extract-text-webpack-plugin": "2.1.0",
"file-loader": "0.11.1",
"history": "4.6.1",
"jest": "20.0.4",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"node-noop": "1.0.0",
Expand All @@ -33,6 +50,7 @@
"redux": "3.6.0",
"redux-thunk": "2.2.0",
"style-loader": "0.17.0",
"ts-jest": "20.0.6",
"typescript": "2.3.2",
"url-loader": "0.5.8",
"webpack": "2.5.1",
Expand Down
13 changes: 11 additions & 2 deletions templates/package-builder/src/yeoman/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ const testSpecificPaths = [
const testSpecificNpmPackages = [
"@types/chai",
"@types/jasmine",
"@types/jest",
"chai",
"jasmine-core",
"jest",
"karma",
"karma-chai",
"karma-chrome-launcher",
"karma-cli",
"karma-jasmine",
"karma-webpack"
"karma-webpack",
"ts-jest"
];

type YeomanPrompt = (opt: yeoman.IPromptOptions | yeoman.IPromptOptions[], callback: (answers: any) => void) => void;
Expand All @@ -47,7 +50,7 @@ const templates: TemplateConfig[] = [
{ value: 'aurelia', rootDir: 'aurelia', name: 'Aurelia', tests: false },
{ value: 'knockout', rootDir: 'knockout', name: 'Knockout', tests: false },
{ value: 'react', rootDir: 'react', name: 'React', tests: false },
{ value: 'react-redux', rootDir: 'react-redux', name: 'React with Redux', tests: false },
{ value: 'react-redux', rootDir: 'react-redux', name: 'React with Redux', tests: true },
{ value: 'vue', rootDir: 'vue', name: 'Vue', tests: false }
];

Expand Down Expand Up @@ -247,6 +250,12 @@ function rewritePackageJson(contents, includeTests) {
delete contents.scripts;
}
}

// Delete 'jest' section
const jest = contents.jest;
if (jest) {
delete contents.jest;
}
}

return contents;
Expand Down