Browse Source

jest works without babelrc

Daniel Zlotin 7 years ago
parent
commit
41d085aed0
3 changed files with 24 additions and 7 deletions
  1. 0
    5
      .babelrc
  2. 11
    2
      package.json
  3. 13
    0
      src2/env.test.js

+ 0
- 5
.babelrc View File

1
-{
2
-  "presets": [
3
-    "react-native"
4
-  ]
5
-}

+ 11
- 2
package.json View File

21
   "scripts": {
21
   "scripts": {
22
     "build": ":",
22
     "build": ":",
23
     "lint": "eslint src2",
23
     "lint": "eslint src2",
24
-    "test:js": "jest --coverage",
24
+    "test:js": "BABEL_ENV=test jest --coverage",
25
     "test:android": "cd android && ./gradlew clean testDebugUnitTest",
25
     "test:android": "cd android && ./gradlew clean testDebugUnitTest",
26
     "test:ios": ":",
26
     "test:ios": ":",
27
     "pretest": "npm run lint",
27
     "pretest": "npm run lint",
28
     "test": "npm run test:js && npm run test:android && npm run test:ios",
28
     "test": "npm run test:js && npm run test:android && npm run test:ios",
29
-    "test:watch": "jest --coverage --watch",
29
+    "test:watch": "BABEL_ENV=test jest --coverage --watch",
30
     "release": ": #npm version prerelease && npm publish --tag next && npm view react-native-navigation dist-tags && git push"
30
     "release": ": #npm version prerelease && npm publish --tag next && npm view react-native-navigation dist-tags && git push"
31
   },
31
   },
32
   "peerDependencies": {
32
   "peerDependencies": {
53
     "jest-cli": "17.x.x",
53
     "jest-cli": "17.x.x",
54
     "react-test-renderer": "15.4.1"
54
     "react-test-renderer": "15.4.1"
55
   },
55
   },
56
+  "babel": {
57
+    "env": {
58
+      "test": {
59
+        "presets": [
60
+          "react-native"
61
+        ]
62
+      }
63
+    }
64
+  },
56
   "jest": {
65
   "jest": {
57
     "preset": "react-native",
66
     "preset": "react-native",
58
     "testPathDirs": [
67
     "testPathDirs": [

+ 13
- 0
src2/env.test.js View File

1
+describe('test environment', () => {
2
+  it('handles object spread', () => {
3
+    const {x, y, ...z} = {x: 1, y: 2, a: 3, b: 4};
4
+    expect(x).toEqual(1);
5
+    expect(y).toEqual(2);
6
+    expect(z).toEqual({a: 3, b: 4});
7
+  });
8
+
9
+  it('handles async await', async() => {
10
+    const result = await new Promise((r) => r('hello'));
11
+    expect(result).toEqual('hello');
12
+  });
13
+});