Closed
Description
🐛 Bug Report
UIManager.js mutates NativeModules, which is mocked by setup.js. The mutation is done in a way that is not idempotent, causing fields of the UIManager to be undefined on the second run.
In an application, UIManager.js is run just once because all modules are singletons in JS. The exception is when we take over the module system with something like Jest. Calling jest.resetModules()
clears the module cache, which includes UIManager.js but not setup.js. As a result, the second time UIManager.js is run, it gets an already mutated version of NativeModules.
To Reproduce
Write a Jest test with two specs loading the UIManager and jest.resetModules()
in an afterEach
block.
Expected Behavior
jest.resetModules()
should not cause RN tests to fail.
Code Example
afterEach(() => {
jest.resetModules();
});
it(`a`, () => {
require('react-native').findNodeHandle;
});
it(`b`, () => {
require('react-native').findNodeHandle;
});
Environment
This is with RN 0.59.3.