mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 15:45:32 +00:00
[ReactNative] Fix dimensions in jest tests
This commit is contained in:
parent
46db1826c5
commit
a2dd7fc69f
@ -29,6 +29,7 @@ var NativeModules = {
|
|||||||
UIManager: {
|
UIManager: {
|
||||||
customBubblingEventTypes: {},
|
customBubblingEventTypes: {},
|
||||||
customDirectEventTypes: {},
|
customDirectEventTypes: {},
|
||||||
|
Dimensions: {},
|
||||||
},
|
},
|
||||||
AsyncLocalStorage: {
|
AsyncLocalStorage: {
|
||||||
getItem: jest.genMockFunction(),
|
getItem: jest.genMockFunction(),
|
||||||
|
@ -20,7 +20,7 @@ var dimensions = NativeModules.UIManager.Dimensions;
|
|||||||
// We calculate the window dimensions in JS so that we don't encounter loss of
|
// 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
|
// precision in transferring the dimensions (which could be non-integers) over
|
||||||
// the bridge.
|
// the bridge.
|
||||||
if (dimensions.windowPhysicalPixels) {
|
if (dimensions && dimensions.windowPhysicalPixels) {
|
||||||
// parse/stringify => Clone hack
|
// parse/stringify => Clone hack
|
||||||
dimensions = JSON.parse(JSON.stringify(dimensions));
|
dimensions = JSON.parse(JSON.stringify(dimensions));
|
||||||
|
|
||||||
|
23
Libraries/Utilities/__mocks__/ErrorUtils.js
Normal file
23
Libraries/Utilities/__mocks__/ErrorUtils.js
Normal file
@ -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;
|
20
Libraries/Utilities/__mocks__/PixelRatio.js
Normal file
20
Libraries/Utilities/__mocks__/PixelRatio.js
Normal file
@ -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;
|
Loading…
x
Reference in New Issue
Block a user