Skip to content

Commit

Permalink
Add test and mocks
Browse files Browse the repository at this point in the history
Mock UIManager

Comment out dontMock that actually needs mocking
  • Loading branch information
sebmarkbage committed Apr 20, 2016
1 parent 91e62c7 commit d8e8ea5
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// Noop

// TODO: Move all initialization callers back into react-native
16 changes: 16 additions & 0 deletions src/renderers/native/ReactNative/__mocks__/InteractionManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// TODO: Figure out a way to drop this dependency

var InteractionManager = {};

module.exports = InteractionManager;
14 changes: 14 additions & 0 deletions src/renderers/native/ReactNative/__mocks__/JSTimersExecution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// Noop

// TODO: Move all initialization callers back into react-native
16 changes: 16 additions & 0 deletions src/renderers/native/ReactNative/__mocks__/Platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// Mock of the Native Hooks

var Platform = {};

module.exports = Platform;
14 changes: 14 additions & 0 deletions src/renderers/native/ReactNative/__mocks__/RCTEventEmitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// Noop

// TODO: Move all initialization callers back into react-native
14 changes: 14 additions & 0 deletions src/renderers/native/ReactNative/__mocks__/RCTLog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// Noop

// TODO: Move all initialization callers back into react-native
17 changes: 17 additions & 0 deletions src/renderers/native/ReactNative/__mocks__/TextInputState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// Mock of the Native Hooks
// TODO: Should this move into the components themselves? E.g. focusable

var TextInputState = {};

module.exports = TextInputState;
21 changes: 21 additions & 0 deletions src/renderers/native/ReactNative/__mocks__/UIManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// Mock of the Native Hooks

var RCTUIManager = {
createView: jest.genMockFunction(),
setChildren: jest.genMockFunction(),
manageChildren: jest.genMockFunction(),
updateView: jest.genMockFunction(),
};

module.exports = RCTUIManager;
63 changes: 63 additions & 0 deletions src/renderers/native/ReactNative/__mocks__/deepDiffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// TODO: Move deepDiffer into react

var deepDiffer = function(one: any, two: any): bool {
if (one === two) {
// Short circuit on identical object references instead of traversing them.
return false;
}
if ((typeof one === 'function') && (typeof two === 'function')) {
// We consider all functions equal
return false;
}
if ((typeof one !== 'object') || (one === null)) {
// Primitives can be directly compared
return one !== two;
}
if ((typeof two !== 'object') || (two === null)) {
// We know they are different because the previous case would have triggered
// otherwise.
return true;
}
if (one.constructor !== two.constructor) {
return true;
}
if (Array.isArray(one)) {
// We know two is also an array because the constructors are equal
var len = one.length;
if (two.length !== len) {
return true;
}
for (var ii = 0; ii < len; ii++) {
if (deepDiffer(one[ii], two[ii])) {
return true;
}
}
} else {
for (var key in one) {
if (deepDiffer(one[key], two[key])) {
return true;
}
}
for (var twoKey in two) {
// The only case we haven't checked yet is keys that are in two but aren't
// in one, which means they are different.
if (one[twoKey] === undefined && two[twoKey] !== undefined) {
return true;
}
}
}
return false;
};

module.exports = deepDiffer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// TODO: move into react or fbjs

var deepFreezeAndThrowOnMutationInDev = function() { };

module.exports = deepFreezeAndThrowOnMutationInDev;
16 changes: 16 additions & 0 deletions src/renderers/native/ReactNative/__mocks__/flattenStyle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// TODO: Move flattenStyle into react

var flattenStyle = function() { };

module.exports = flattenStyle;
18 changes: 18 additions & 0 deletions src/renderers/native/ReactNative/__mocks__/merge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

// TODO: Replace all callers with spread

var merge = function(a, b) {
return {...a, ...b};
};

module.exports = merge;
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

jest.dontMock('ReactNativeAttributePayload');
jest.dontMock('ReactNativePropRegistry');
jest.dontMock('deepDiffer');
jest.dontMock('flattenStyle');
// jest.dontMock('deepDiffer');
// jest.dontMock('flattenStyle');

var ReactNativeAttributePayload = require('ReactNativeAttributePayload');
var ReactNativePropRegistry = require('ReactNativePropRegistry');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails react-core
*/

'use strict';

var React;
var ReactNative;
var createReactNativeComponentClass;

describe('ReactNative', function() {
beforeEach(function() {
React = require('React');
ReactNative = require('ReactNative');
createReactNativeComponentClass = require('createReactNativeComponentClass');
});

it('should be able to create and render a native component', function() {
var View = createReactNativeComponentClass({
validAttributes: { foo: true },
uiViewClassName: 'View',
});

ReactNative.render(<View foo="test" />, 1);
});

});

0 comments on commit d8e8ea5

Please sign in to comment.