diff --git a/templates/ReactReduxSpa/ClientApp/store/Counter.spec.ts b/templates/ReactReduxSpa/ClientApp/store/Counter.spec.ts new file mode 100644 index 00000000..b01dd54e --- /dev/null +++ b/templates/ReactReduxSpa/ClientApp/store/Counter.spec.ts @@ -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 }); + }); +}); \ No newline at end of file diff --git a/templates/ReactReduxSpa/package.json b/templates/ReactReduxSpa/package.json index 56edd57c..f82eab8c 100644 --- a/templates/ReactReduxSpa/package.json +++ b/templates/ReactReduxSpa/package.json @@ -1,8 +1,24 @@ { "name": "WebApplicationBasic", "version": "0.0.0", + "scripts": { + "test": "jest" + }, + "jest": { + "transform": { + ".(ts|tsx)": "/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", @@ -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", @@ -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", diff --git a/templates/package-builder/src/yeoman/app/index.ts b/templates/package-builder/src/yeoman/app/index.ts index fadda587..e9163c7d 100644 --- a/templates/package-builder/src/yeoman/app/index.ts +++ b/templates/package-builder/src/yeoman/app/index.ts @@ -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; @@ -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 } ]; @@ -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;