Browse Source

wallaby broken by jest, pending issues

Daniel Zlotin 8 years ago
parent
commit
7854fde4ae
7 changed files with 1035 additions and 1060 deletions
  1. 4
    1
      package.json
  2. 8
    0
      src2/Navigation.js
  3. 2
    0
      src2/Navigation.test.js
  4. 9
    9
      src2/containers/ContainerRegistry.js
  5. 26
    14
      src2/containers/ContainerRegistry.test.js
  6. 4
    0
      wallaby.js
  7. 982
    1036
      yarn.lock

+ 4
- 1
package.json View File

44
     "babel-polyfill": "6.x.x",
44
     "babel-polyfill": "6.x.x",
45
     "babel-preset-react-native": "1.x.x",
45
     "babel-preset-react-native": "1.x.x",
46
     "babel-register": "6.x.x",
46
     "babel-register": "6.x.x",
47
+    "babel-jest": "17.x.x",
47
     "eslint": "3.x.x",
48
     "eslint": "3.x.x",
48
     "eslint-plugin-babel": "3.x.x",
49
     "eslint-plugin-babel": "3.x.x",
49
     "eslint-plugin-react": "6.x.x",
50
     "eslint-plugin-react": "6.x.x",
54
     "react-test-renderer": "15.3.2"
55
     "react-test-renderer": "15.3.2"
55
   },
56
   },
56
   "jest": {
57
   "jest": {
58
+    "preset": "jest-react-native",
57
     "resetMocks": true,
59
     "resetMocks": true,
58
-    "resetModules": true
60
+    "resetModules": true,
61
+    "verbose": true
59
   }
62
   }
60
 }
63
 }

+ 8
- 0
src2/Navigation.js View File

41
 export function dismissInAppNotification(params) {
41
 export function dismissInAppNotification(params) {
42
   //
42
   //
43
 }
43
 }
44
+
45
+export function popToRoot(params) {
46
+  //
47
+}
48
+
49
+export function newStack(params) {
50
+  //
51
+}

+ 2
- 0
src2/Navigation.test.js View File

13
       Navigation.startApp,
13
       Navigation.startApp,
14
       Navigation.push,
14
       Navigation.push,
15
       Navigation.pop,
15
       Navigation.pop,
16
+      Navigation.popToRoot,
17
+      Navigation.newStack,
16
       Navigation.showModal,
18
       Navigation.showModal,
17
       Navigation.dismissModal,
19
       Navigation.dismissModal,
18
       Navigation.dismissAllModals,
20
       Navigation.dismissAllModals,

+ 9
- 9
src2/containers/ContainerRegistry.js View File

1
-import React from 'react';
2
-import {AppRegistry, Component} from 'react-native';
1
+import React, {Component} from 'react';
2
+import {AppRegistry} from 'react-native';
3
 
3
 
4
 export function registerContainer(containerKey, getContainerFunc) {
4
 export function registerContainer(containerKey, getContainerFunc) {
5
-  const OrigContainer = getContainerFunc();
6
-  const WrappedContainer = wrapContainer(OrigContainer);
5
+  const OriginalContainer = getContainerFunc();
6
+  const WrappedContainer = wrapContainer(OriginalContainer);
7
   AppRegistry.registerComponent(containerKey, () => WrappedContainer);
7
   AppRegistry.registerComponent(containerKey, () => WrappedContainer);
8
 }
8
 }
9
 
9
 
10
-function wrapContainer(OrigComponent) {
10
+function wrapContainer(OriginalContainer) {
11
   return class extends Component {
11
   return class extends Component {
12
-    //constructor(props) {
13
-    //  super(props);
14
-    //}
12
+    constructor(props) {
13
+      super(props);
14
+    }
15
 
15
 
16
     render() {
16
     render() {
17
       return (
17
       return (
18
-        <OrigComponent/>
18
+        <OriginalContainer/>
19
       );
19
       );
20
     }
20
     }
21
   };
21
   };

+ 26
- 14
src2/containers/ContainerRegistry.test.js View File

1
+import {AppRegistry, Text} from 'react-native';
2
+import React, {Component} from 'react';
3
+
4
+class MyContainer extends Component {
5
+  render() {
6
+    return (
7
+      <Text>{'Hello, World!'}</Text>
8
+    );
9
+  }
10
+}
11
+
12
+import renderer from 'react-test-renderer';
13
+
1
 describe('ComponentRegistry', () => {
14
 describe('ComponentRegistry', () => {
2
   let uut;
15
   let uut;
3
-  let AppRegistry;
4
-  let MyContainer, Component;
5
 
16
 
6
   beforeEach(() => {
17
   beforeEach(() => {
7
-    AppRegistry = {registerComponent: jest.fn()};
8
-    Component = class {
9
-      //
10
-    };
11
-
12
-    jest.mock('react', () => ({}));
13
-    jest.mock('react-native', () => ({AppRegistry, Component}));
18
+    AppRegistry.registerComponent = jest.fn(AppRegistry.registerComponent);
19
+    //jest.mock('react-native', () => ({AppRegistry}));
14
     uut = require('./ContainerRegistry');
20
     uut = require('./ContainerRegistry');
15
-
16
-    MyContainer = class extends Component {
17
-      //
18
-    };
19
   });
21
   });
20
 
22
 
21
-  it('registers container component into AppRegistry', () => {
23
+  xit('registers container component into AppRegistry', () => {
22
     expect(AppRegistry.registerComponent).not.toHaveBeenCalled();
24
     expect(AppRegistry.registerComponent).not.toHaveBeenCalled();
23
 
25
 
24
     uut.registerContainer('example.MyContainer', () => MyContainer);
26
     uut.registerContainer('example.MyContainer', () => MyContainer);
26
     expect(AppRegistry.registerComponent).toHaveBeenCalledTimes(1);
28
     expect(AppRegistry.registerComponent).toHaveBeenCalledTimes(1);
27
     expect(AppRegistry.registerComponent.mock.calls[0][0]).toEqual('example.MyContainer');
29
     expect(AppRegistry.registerComponent.mock.calls[0][0]).toEqual('example.MyContainer');
28
   });
30
   });
31
+
32
+  it('wraps the container', () => {
33
+    uut.registerContainer('example.MyContainer', () => MyContainer);
34
+
35
+    const WrappedClass = AppRegistry.registerComponent.mock.calls[0][1]();
36
+    const tree = renderer.create(
37
+      <WrappedClass/>
38
+    );
39
+    console.log(tree.toJSON())
40
+  });
29
 });
41
 });

+ 4
- 0
wallaby.js View File

11
     testFramework: 'jest',
11
     testFramework: 'jest',
12
 
12
 
13
     files: [
13
     files: [
14
+      'package.json',
15
+      'node_modules/react/**/*.js',
16
+      'node_modules/*jest*/**/*.js',
14
       'src2/**/*.js',
17
       'src2/**/*.js',
15
       '!src2/**/*.test.js'
18
       '!src2/**/*.test.js'
16
     ],
19
     ],
25
 
28
 
26
     setup: function(w) {
29
     setup: function(w) {
27
       require('babel-polyfill');
30
       require('babel-polyfill');
31
+      w.testFramework.configure(require('./package.json').jest);
28
     }
32
     }
29
   };
33
   };
30
 };
34
 };

+ 982
- 1036
yarn.lock
File diff suppressed because it is too large
View File