-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
Summary: A while back Jest introduced `jest.requireActual` and `jest.requireMock` which are aliases to `require.requireActual` and `require.requireMock`. We believe that users should use official Jest API and are planning to deprecate the latter. Pull Request resolved: #21849 Differential Revision: D10448849 Pulled By: TheSavior fbshipit-source-id: 34fffde97f48c26098c74ee222a56d99071703a6
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,17 @@ | |
|
||
'use strict'; | ||
|
||
const MockNativeMethods = require.requireActual('./MockNativeMethods'); | ||
const mockComponent = require.requireActual('./mockComponent'); | ||
const MockNativeMethods = jest.requireActual('./MockNativeMethods'); | ||
const mockComponent = jest.requireActual('./mockComponent'); | ||
|
||
require.requireActual('../Libraries/polyfills/babelHelpers.js'); | ||
require.requireActual('../Libraries/polyfills/Object.es7.js'); | ||
require.requireActual('../Libraries/polyfills/error-guard'); | ||
jest.requireActual('../Libraries/polyfills/babelHelpers.js'); | ||
jest.requireActual('../Libraries/polyfills/Object.es7.js'); | ||
jest.requireActual('../Libraries/polyfills/error-guard'); | ||
|
||
global.__DEV__ = true; | ||
|
||
global.Promise = require.requireActual('promise'); | ||
global.regeneratorRuntime = require.requireActual( | ||
'regenerator-runtime/runtime', | ||
); | ||
global.Promise = jest.requireActual('promise'); | ||
global.regeneratorRuntime = jest.requireActual('regenerator-runtime/runtime'); | ||
|
||
global.requestAnimationFrame = function(callback) { | ||
return setTimeout(callback, 0); | ||
|
@@ -42,12 +40,12 @@ jest | |
.mock('TextInput', () => mockComponent('TextInput')) | ||
.mock('Modal', () => mockComponent('Modal')) | ||
.mock('View', () => mockComponent('View', MockNativeMethods)) | ||
.mock('RefreshControl', () => require.requireMock('RefreshControlMock')) | ||
.mock('ScrollView', () => require.requireMock('ScrollViewMock')) | ||
.mock('RefreshControl', () => jest.requireMock('RefreshControlMock')) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
thymikee
Author
Contributor
|
||
.mock('ScrollView', () => jest.requireMock('ScrollViewMock')) | ||
.mock('ActivityIndicator', () => mockComponent('ActivityIndicator')) | ||
.mock('ListView', () => require.requireMock('ListViewMock')) | ||
.mock('ListView', () => jest.requireMock('ListViewMock')) | ||
.mock('ListViewDataSource', () => { | ||
const DataSource = require.requireActual('ListViewDataSource'); | ||
const DataSource = jest.requireActual('ListViewDataSource'); | ||
DataSource.prototype.toJSON = function() { | ||
function ListViewDataSource(dataBlob) { | ||
this.items = 0; | ||
|
@@ -68,9 +66,7 @@ jest | |
return DataSource; | ||
}) | ||
.mock('AnimatedImplementation', () => { | ||
const AnimatedImplementation = require.requireActual( | ||
'AnimatedImplementation', | ||
); | ||
const AnimatedImplementation = jest.requireActual('AnimatedImplementation'); | ||
const oldCreate = AnimatedImplementation.createAnimatedComponent; | ||
AnimatedImplementation.createAnimatedComponent = function(Component) { | ||
const Wrapped = oldCreate(Component); | ||
|
@@ -80,7 +76,7 @@ jest | |
return AnimatedImplementation; | ||
}) | ||
.mock('ReactNative', () => { | ||
const ReactNative = require.requireActual('ReactNative'); | ||
const ReactNative = jest.requireActual('ReactNative'); | ||
const NativeMethodsMixin = | ||
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED | ||
.NativeMethodsMixin; | ||
|
Hi @thymikee
We've occurred the
Cannot find module 'setupDevtools' from 'setup.js' in react-native/jest/setup.js
after upgrading RN to 0.57.5. I tried the solutions in #19859, but none of it helped.By digging into the
react-native/jest/setup.js
. I found if I changejest.mock('setupDevtools')
tojest.mock('../Libraries/Core/Devtools/setupDevtools.js')
.This error will be gone.
But another one
Cannot find module 'InitializeCore'
showed up. Changing this tojest.mock('../Libraries/Core/InitializeCore.js')
resolved the error too. then next one,Cannot find module 'Image'
appeared. So it looks like something wrong when loading the modules inside../Libraries
.Do you happen to know how
mock
find the module without specifying the exact path? Is there a configuration or something like this to config thesetup.js
to load modules from../Libraries
as a default prefix path?