Skip to content

Commit af15e00

Browse files
committed
typescript jest files are now working
1 parent 010c267 commit af15e00

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ node setup.js
1919
- [TypeScript](https://github.com/Microsoft/TypeScript)
2020
- [React Native TypeScript Transformer](https://github.com/ds300/react-native-typescript-transformer)
2121
- [Type definitions for React & React Native](https://github.com/DefinitelyTyped/DefinitelyTyped)
22+
- [TS Jest](https://github.com/kulshekhar/ts-jest)
2223
- [TSLint](https://github.com/palantir/tslint)
2324
- [TSLint React](https://github.com/palantir/tslint-react)
2425

@@ -28,10 +29,6 @@ This template always uses the latest versions of the dependencies at the time wh
2829

2930
The React Native CLI supports automatic installation of production dependencies only. Since TypeScript and the other dependencies are dev dependencies, the setup script is being used to install those. It also takes care of obsolete files like the `.flowconfig` and the `setup.js` itself after the setup.
3031

31-
### What about Jest?
32-
33-
This template does not cover Jest yet. For more info on the current status check the [open issue](https://github.com/emin93/react-native-template-typescript/issues/1).
34-
3532
### How will this template affect the React Native CLI workflow?
3633

3734
The React Native CLI will do everything just as without a template and afterwards overwrite the files with the ones from this template. This means you don't have to worry about incompatibility issues with later React Native upgrades.

__tests__/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from "react";
22
import "react-native";
3-
import renderer from "react-test-renderer";
3+
import { create } from "react-test-renderer";
44

55
import App from "../src/App";
66

77
it("renders correctly", () => {
8-
const tree = renderer.create(<App exampleProp="helloWorld" />);
8+
const tree = create(<App exampleProp="helloWorld" />);
99
});

jest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"transform": {
3+
"^.+\\.tsx?$": "ts-jest"
4+
},
5+
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
6+
"moduleFileExtensions": [
7+
"ts",
8+
"tsx",
9+
"js",
10+
"jsx",
11+
"json",
12+
"node"
13+
],
14+
"modulePaths": ["<rootDir>"]
15+
}

setup.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@ const path = require('path');
33
const { execSync } = require('child_process');
44

55
const packageJson = require('./package.json');
6+
const jestJson = require('./jest.json');
67
const devDependencies = require('./devDependencies.json');
78

89
const deleteFile = (fileName) => fs.unlinkSync(path.join(process.cwd(), fileName));
910
const writeFile = (fileName, data) => fs.writeFileSync(path.join(process.cwd(), fileName), data);
1011

1112
packageJson.scripts.start = `${packageJson.scripts.start} --config ../../../../rn-cli.config.js`;
1213
packageJson.scripts.lint = 'tslint -c tslint.json "src/**/*.{ts,tsx}"';
14+
packageJson.jest = Object.assign(packageJson.jest, jestJson);
1315
writeFile('package.json', JSON.stringify(packageJson, null, 2));
1416

1517
execSync(`npm i ${devDependencies.join(' ')} --save-dev --save-exact`);
16-
execSync(`npm uninstall babel-jest babel-preset-react-native --save`);
1718

1819
deleteFile('App.js');
1920
deleteFile('__tests__/App.js');
2021
deleteFile('.flowconfig');
21-
deleteFile('.babelrc');
2222
deleteFile('devDependencies.json');
23+
deleteFile('jest.json');
2324
deleteFile('README.md');
2425
deleteFile('LICENSE');
2526
deleteFile('setup.js');

0 commit comments

Comments
 (0)