diff --git a/Libraries/BatchedBridge/BatchedBridgedModules/__mocks__/NativeModules.js b/Libraries/BatchedBridge/BatchedBridgedModules/__mocks__/NativeModules.js index 28da1bc32..7eed36e01 100644 --- a/Libraries/BatchedBridge/BatchedBridgedModules/__mocks__/NativeModules.js +++ b/Libraries/BatchedBridge/BatchedBridgedModules/__mocks__/NativeModules.js @@ -29,6 +29,7 @@ var NativeModules = { UIManager: { customBubblingEventTypes: {}, customDirectEventTypes: {}, + Dimensions: {}, }, AsyncLocalStorage: { getItem: jest.genMockFunction(), diff --git a/Libraries/Utilities/Dimensions.js b/Libraries/Utilities/Dimensions.js index fe28a7684..b93000a33 100644 --- a/Libraries/Utilities/Dimensions.js +++ b/Libraries/Utilities/Dimensions.js @@ -20,7 +20,7 @@ var dimensions = NativeModules.UIManager.Dimensions; // We calculate the window dimensions in JS so that we don't encounter loss of // precision in transferring the dimensions (which could be non-integers) over // the bridge. -if (dimensions.windowPhysicalPixels) { +if (dimensions && dimensions.windowPhysicalPixels) { // parse/stringify => Clone hack dimensions = JSON.parse(JSON.stringify(dimensions)); diff --git a/Libraries/Utilities/__mocks__/ErrorUtils.js b/Libraries/Utilities/__mocks__/ErrorUtils.js new file mode 100644 index 000000000..99db79177 --- /dev/null +++ b/Libraries/Utilities/__mocks__/ErrorUtils.js @@ -0,0 +1,23 @@ +// This mock only provides short-circuited methods of applyWithGuard and guard. +// A lot of modules rely on these two functions. This mock relieves their tests +// from depending on the real ErrorUtils module. If you need real error handling +// don't use this mock. +'use strict'; + +function execute(fun, context, args) { + return fun.apply(context, args); +}; + +function reportError(error) { + throw error; +} + +var ErrorUtils = { + apply: jest.genMockFunction().mockImplementation(execute), + applyWithGuard: jest.genMockFunction().mockImplementation(execute), + inGuard: jest.genMockFunction().mockReturnValue(true), + reportError: jest.genMockFunction().mockImplementation(reportError), + setGlobalHandler: jest.genMockFunction(), +}; + +module.exports = ErrorUtils; diff --git a/Libraries/Utilities/__mocks__/PixelRatio.js b/Libraries/Utilities/__mocks__/PixelRatio.js new file mode 100644 index 000000000..bcf04d7fe --- /dev/null +++ b/Libraries/Utilities/__mocks__/PixelRatio.js @@ -0,0 +1,20 @@ +/** + * Copyright 2004-present Facebook. All Rights Reserved. + */ +'use strict'; + +var PixelRatio = { + startDetecting: function () { + // noop for our implementation + }, + + get: function() { + return 2; + }, + + getPixelSizeForLayoutSize: function (layoutSize) { + return Math.round(layoutSize * PixelRatio.get()); + } +}; + +module.exports = PixelRatio;