You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Fantom tests to avoid logging errors to test output (#51346)
Summary:
Pull Request resolved: #51346
Changelog: [internal]
I saw that this test was logging errors to the console, which is considered a bad practice in Jest tests.
This prevents the logs from being printed in the test output and also adds assertions to verify what should be logged.
Reviewed By: rshest
Differential Revision: D74803463
fbshipit-source-id: 9c840a51e0e616a6bb15b7a40b3a6937fcb88b64
Copy file name to clipboardExpand all lines: packages/react-native-fantom/src/__tests__/Fantom-itest.js
+40-18
Original file line number
Diff line number
Diff line change
@@ -245,29 +245,51 @@ describe('Fantom', () => {
245
245
Fantom.runWorkLoop();
246
246
});
247
247
248
-
it('should throw an error when running a task with LogBox installed',()=>{
249
-
LogBox.install();
248
+
describe('when LogBox is installed',()=>{
249
+
letoriginalConsoleError;
250
250
251
-
expect(()=>{
252
-
Fantom.runTask(()=>{});
253
-
}).toThrow(
254
-
'Cannot run work loop while LogBox is installed, as LogBox intercepts errors thrown in tests.'+
255
-
' If you are installing LogBox unintentionally using `InitializeCore`, replace it with `@react-native/fantom/src/setUpDefaultReactNativeEnvironment` to avoid this problem.',
256
-
);
251
+
beforeEach(()=>{
252
+
LogBox.install();
257
253
258
-
// We need to do this cleanup or Fantom will fail the test for us.
259
-
LogBox.uninstall();
260
-
Fantom.runWorkLoop();
261
-
});
254
+
originalConsoleError=console.error;
262
255
263
-
it('should not throw an error when running a task with LogBox installed if setLogBoxCheckEnabled is set to false',()=>{
264
-
LogBox.install();
256
+
// $FlowExpectedError[cannot-write]
257
+
console.error=jest.fn();
258
+
});
265
259
266
-
Fantom.setLogBoxCheckEnabled(false);
260
+
afterEach(()=>{
261
+
LogBox.uninstall();
267
262
268
-
expect(()=>{
269
-
Fantom.runTask(()=>{});
270
-
}).not.toThrow();
263
+
// $FlowExpectedError[cannot-write]
264
+
console.error=originalConsoleError;
265
+
});
266
+
267
+
it('should throw an error when running a task',()=>{
268
+
constexpectedErrorMessage=
269
+
'Cannot run work loop while LogBox is installed, as LogBox intercepts errors thrown in tests.'+
270
+
' If you are installing LogBox unintentionally using `InitializeCore`, replace it with `@react-native/fantom/src/setUpDefaultReactNativeEnvironment` to avoid this problem.';
0 commit comments