@samitouri / QOS-React / commits / d8e8ea5cbb

Add test and mocks

Mock UIManager Comment out dontMock that actually needs mocking

Sebastian Markbage committed Mar 24, 2016 at 18:58 UTC d8e8ea5cbbfae10f1eb0ccfaeb7e8b0668020083
14 files changed +275 -2
src/renderers/native/ReactNative/__mocks__/InitializeJavaScriptAppEngine.js new
+14
@@ -0,0 +1,14 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// Noop
13 +
14 +// TODO: Move all initialization callers back into react-native
src/renderers/native/ReactNative/__mocks__/InteractionManager.js new
+16
@@ -0,0 +1,16 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// TODO: Figure out a way to drop this dependency
13 +
14 +var InteractionManager = {};
15 +
16 +module.exports = InteractionManager;
src/renderers/native/ReactNative/__mocks__/JSTimersExecution.js new
+14
@@ -0,0 +1,14 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// Noop
13 +
14 +// TODO: Move all initialization callers back into react-native
src/renderers/native/ReactNative/__mocks__/Platform.js new
+16
@@ -0,0 +1,16 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// Mock of the Native Hooks
13 +
14 +var Platform = {};
15 +
16 +module.exports = Platform;
src/renderers/native/ReactNative/__mocks__/RCTEventEmitter.js new
+14
@@ -0,0 +1,14 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// Noop
13 +
14 +// TODO: Move all initialization callers back into react-native
src/renderers/native/ReactNative/__mocks__/RCTLog.js new
+14
@@ -0,0 +1,14 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// Noop
13 +
14 +// TODO: Move all initialization callers back into react-native
src/renderers/native/ReactNative/__mocks__/TextInputState.js new
+17
@@ -0,0 +1,17 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// Mock of the Native Hooks
13 +// TODO: Should this move into the components themselves? E.g. focusable
14 +
15 +var TextInputState = {};
16 +
17 +module.exports = TextInputState;
src/renderers/native/ReactNative/__mocks__/UIManager.js new
+21
@@ -0,0 +1,21 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// Mock of the Native Hooks
13 +
14 +var RCTUIManager = {
15 + createView: jest.genMockFunction(),
16 + setChildren: jest.genMockFunction(),
17 + manageChildren: jest.genMockFunction(),
18 + updateView: jest.genMockFunction(),
19 +};
20 +
21 +module.exports = RCTUIManager;
src/renderers/native/ReactNative/__mocks__/deepDiffer.js new
+63
@@ -0,0 +1,63 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// TODO: Move deepDiffer into react
13 +
14 +var deepDiffer = function(one: any, two: any): bool {
15 + if (one === two) {
16 + // Short circuit on identical object references instead of traversing them.
17 + return false;
18 + }
19 + if ((typeof one === 'function') && (typeof two === 'function')) {
20 + // We consider all functions equal
21 + return false;
22 + }
23 + if ((typeof one !== 'object') || (one === null)) {
24 + // Primitives can be directly compared
25 + return one !== two;
26 + }
27 + if ((typeof two !== 'object') || (two === null)) {
28 + // We know they are different because the previous case would have triggered
29 + // otherwise.
30 + return true;
31 + }
32 + if (one.constructor !== two.constructor) {
33 + return true;
34 + }
35 + if (Array.isArray(one)) {
36 + // We know two is also an array because the constructors are equal
37 + var len = one.length;
38 + if (two.length !== len) {
39 + return true;
40 + }
41 + for (var ii = 0; ii < len; ii++) {
42 + if (deepDiffer(one[ii], two[ii])) {
43 + return true;
44 + }
45 + }
46 + } else {
47 + for (var key in one) {
48 + if (deepDiffer(one[key], two[key])) {
49 + return true;
50 + }
51 + }
52 + for (var twoKey in two) {
53 + // The only case we haven't checked yet is keys that are in two but aren't
54 + // in one, which means they are different.
55 + if (one[twoKey] === undefined && two[twoKey] !== undefined) {
56 + return true;
57 + }
58 + }
59 + }
60 + return false;
61 +};
62 +
63 +module.exports = deepDiffer;
src/renderers/native/ReactNative/__mocks__/deepFreezeAndThrowOnMutationInDev.js new
+16
@@ -0,0 +1,16 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// TODO: move into react or fbjs
13 +
14 +var deepFreezeAndThrowOnMutationInDev = function() { };
15 +
16 +module.exports = deepFreezeAndThrowOnMutationInDev;
src/renderers/native/ReactNative/__mocks__/flattenStyle.js new
+16
@@ -0,0 +1,16 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// TODO: Move flattenStyle into react
13 +
14 +var flattenStyle = function() { };
15 +
16 +module.exports = flattenStyle;
src/renderers/native/ReactNative/__mocks__/merge.js new
+18
@@ -0,0 +1,18 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +
10 +'use strict';
11 +
12 +// TODO: Replace all callers with spread
13 +
14 +var merge = function(a, b) {
15 + return {...a, ...b};
16 +};
17 +
18 +module.exports = merge;
src/renderers/native/ReactNative/__tests__/ReactNativeAttributePayload-test.js
+2 -2
@@ -11,8 +11,8 @@
11
12 jest.dontMock('ReactNativeAttributePayload');
13 jest.dontMock('ReactNativePropRegistry');
14 -jest.dontMock('deepDiffer');
15 -jest.dontMock('flattenStyle');
14 +// jest.dontMock('deepDiffer');
15 +// jest.dontMock('flattenStyle');
16
17 var ReactNativeAttributePayload = require('ReactNativeAttributePayload');
18 var ReactNativePropRegistry = require('ReactNativePropRegistry');
src/renderers/native/ReactNative/__tests__/ReactNativeMount-test.js new
+34
@@ -0,0 +1,34 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + *
9 + * @emails react-core
10 + */
11 +
12 +'use strict';
13 +
14 +var React;
15 +var ReactNative;
16 +var createReactNativeComponentClass;
17 +
18 +describe('ReactNative', function() {
19 + beforeEach(function() {
20 + React = require('React');
21 + ReactNative = require('ReactNative');
22 + createReactNativeComponentClass = require('createReactNativeComponentClass');
23 + });
24 +
25 + it('should be able to create and render a native component', function() {
26 + var View = createReactNativeComponentClass({
27 + validAttributes: { foo: true },
28 + uiViewClassName: 'View',
29 + });
30 +
31 + ReactNative.render(<View foo="test" />, 1);
32 + });
33 +
34 +});