瀏覽代碼

babel and jest

Daniel Zlotin 8 年之前
父節點
當前提交
35131813d1
共有 5 個檔案被更改,包括 80 行新增1 行删除
  1. 5
    0
      .babelrc
  2. 6
    1
      package.json
  3. 17
    0
      src2/stores/props/store.js
  4. 22
    0
      src2/stores/props/store.test.js
  5. 30
    0
      wallaby.js

+ 5
- 0
.babelrc 查看文件

@@ -0,0 +1,5 @@
1
+{
2
+  "presets": [
3
+    "react-native"
4
+  ]
5
+}

+ 6
- 1
package.json 查看文件

@@ -21,11 +21,12 @@
21 21
   "scripts": {
22 22
     "build": ":",
23 23
     "lint": "eslint src2",
24
-    "test:js": "jest",
24
+    "test:js": "jest --coverage",
25 25
     "test:android": "cd android && ./gradlew clean testDebugUnitTest",
26 26
     "test:ios": ":",
27 27
     "pretest": "npm run lint",
28 28
     "test": "npm run test:js && npm run test:android && npm run test:ios",
29
+    "test:watch": "jest --coverage --watch",
29 30
     "release": ": #npm version prerelease && npm publish --tag next && npm view react-native-navigation dist-tags && git push"
30 31
   },
31 32
   "peerDependencies": {
@@ -49,5 +50,9 @@
49 50
     "eslint-plugin-react-native": "2.x.x",
50 51
     "jest": "17.x.x",
51 52
     "jest-cli": "17.x.x"
53
+  },
54
+  "jest": {
55
+    "resetMocks": true,
56
+    "resetModules": true
52 57
   }
53 58
 }

+ 17
- 0
src2/stores/props/store.js 查看文件

@@ -0,0 +1,17 @@
1
+import _ from 'lodash';
2
+
3
+const state = {
4
+  propsByScreenId: {}
5
+};
6
+
7
+export const mutators = {
8
+  setPropsForScreenId(screenId, props) {
9
+    _.set(state.propsByScreenId, screenId, props);
10
+  }
11
+};
12
+
13
+export const selectors = {
14
+  getPropsForScreenId(screenId) {
15
+    return _.get(state.propsByScreenId, screenId, {});
16
+  }
17
+};

+ 22
- 0
src2/stores/props/store.test.js 查看文件

@@ -0,0 +1,22 @@
1
+describe('stores/props/store', () => {
2
+  let uut;
3
+
4
+  beforeEach(() => {
5
+    uut = require('./store');
6
+  });
7
+
8
+  it('initial state', () => {
9
+    expect(uut.selectors.getPropsForScreenId('screen1')).toEqual({});
10
+  });
11
+
12
+  it('holds props by screenId', () => {
13
+    uut.mutators.setPropsForScreenId('screen1', {a: 1, b: 2});
14
+    expect(uut.selectors.getPropsForScreenId('screen1')).toEqual({a: 1, b: 2});
15
+  });
16
+
17
+  it('defensive for invalid screenId and props', () => {
18
+    uut.mutators.setPropsForScreenId('screen1', undefined);
19
+    uut.mutators.setPropsForScreenId(undefined, undefined);
20
+    expect(uut.selectors.getPropsForScreenId('screen1')).toEqual({});
21
+  });
22
+});

+ 30
- 0
wallaby.js 查看文件

@@ -0,0 +1,30 @@
1
+/*eslint-disable*/
2
+'use strict';
3
+const babelOptions = JSON.parse(require('fs').readFileSync(`${__dirname}/.babelrc`));
4
+module.exports = function(wallaby) {
5
+  return {
6
+    env: {
7
+      type: 'node',
8
+      runner: 'node'
9
+    },
10
+
11
+    testFramework: 'jest',
12
+
13
+    files: [
14
+      'src2/**/*.js',
15
+      '!src2/**/*.test.js'
16
+    ],
17
+
18
+    tests: [
19
+      'src2/**/*.test.js'
20
+    ],
21
+
22
+    compilers: {
23
+      '**/*.js': wallaby.compilers.babel(babelOptions)
24
+    },
25
+
26
+    setup: function(w) {
27
+      require('babel-polyfill');
28
+    }
29
+  };
30
+};