Skip to content

fix: stabilize unit tests - #1580

Merged
kirillzyusko merged 1 commit into
mainfrom
fix/stabilize-unit-tests
Aug 4, 2026
Merged

fix: stabilize unit tests#1580
kirillzyusko merged 1 commit into
mainfrom
fix/stabilize-unit-tests

Conversation

@kirillzyusko

@kirillzyusko kirillzyusko commented Aug 3, 2026

Copy link
Copy Markdown
Owner

📜 Description

Fixed noisy logs when running unit tests.

💡 Motivation and Context

We had these errors:

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From src/components/KeyboardAwareScrollView/__tests__/selectionOrder.spec.tsx.

    

      at mockState (src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:1180:10)
      at scrollTo (src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:9:28)
      at src/components/KeyboardAwareScrollView/index.tsx:4817:43
      at src/components/KeyboardAwareScrollView/index.tsx:4868:5
      at src/components/KeyboardAwareScrollView/index.tsx:4917:5
      at src/components/KeyboardAwareScrollView/index.tsx:5200:9
      at src/components/KeyboardAwareScrollView/index.tsx:5201:9
      at Timeout._onTimeout (node_modules/react-native-reanimated/src/mockedRequestAnimationFrame.ts:8:12)
/Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:9
      return (_mockState = mockState()).mockScrollTo.apply(_mockState, arguments);
                                                     ^

TypeError: Cannot read properties of undefined (reading 'apply')
    at scrollTo (/Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:9:54)
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:4817:43
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:4868:5
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:4917:5
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:5200:9
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:5201:9
    at Timeout._onTimeout (/Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/node_modules/react-native-reanimated/src/mockedRequestAnimationFrame.ts:8:12)
    at listOnTimeout (node:internal/timers:605:17)
    at processTimers (node:internal/timers:541:7)

Node.js v24.15.0

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From src/components/KeyboardAwareScrollView/__tests__/selectionOrder.spec.tsx.

    

      at mockState (src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:1180:10)
      at scrollTo (src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:9:28)
      at src/components/KeyboardAwareScrollView/index.tsx:4817:43
      at src/components/KeyboardAwareScrollView/index.tsx:4868:5
      at src/components/KeyboardAwareScrollView/index.tsx:4917:5
      at src/components/KeyboardAwareScrollView/index.tsx:5200:9
      at src/components/KeyboardAwareScrollView/index.tsx:5201:9
      at Timeout._onTimeout (node_modules/react-native-reanimated/src/mockedRequestAnimationFrame.ts:8:12)
/Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:9
      return (_mockState = mockState()).mockScrollTo.apply(_mockState, arguments);
                                                     ^

TypeError: Cannot read properties of undefined (reading 'apply')
    at scrollTo (/Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:9:54)
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:4817:43
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:4868:5
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:4917:5
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:5200:9
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:5201:9
    at Timeout._onTimeout (/Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/node_modules/react-native-reanimated/src/mockedRequestAnimationFrame.ts:8:12)
    at listOnTimeout (node:internal/timers:605:17)
    at processTimers (node:internal/timers:541:7)

Node.js v24.15.0

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From src/components/KeyboardAwareScrollView/__tests__/selectionOrder.spec.tsx.

    

      at mockState (src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:1180:10)
      at scrollTo (src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:9:28)
      at src/components/KeyboardAwareScrollView/index.tsx:4817:43
      at src/components/KeyboardAwareScrollView/index.tsx:4868:5
      at src/components/KeyboardAwareScrollView/index.tsx:4917:5
      at src/components/KeyboardAwareScrollView/index.tsx:5200:9
      at src/components/KeyboardAwareScrollView/index.tsx:5201:9
      at Timeout._onTimeout (node_modules/react-native-reanimated/src/mockedRequestAnimationFrame.ts:8:12)
/Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:9
      return (_mockState = mockState()).mockScrollTo.apply(_mockState, arguments);
                                                     ^

TypeError: Cannot read properties of undefined (reading 'apply')
    at scrollTo (/Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/__fixtures__/mocks.tsx:9:54)
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:4817:43
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:4868:5
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:4917:5
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:5200:9
    at /Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/src/components/KeyboardAwareScrollView/index.tsx:5201:9
    at Timeout._onTimeout (/Users/kirylziusko/IdeaProjects/react-native-keyboard-controller/node_modules/react-native-reanimated/src/mockedRequestAnimationFrame.ts:8:12)
    at listOnTimeout (node:internal/timers:605:17)
    at processTimers (node:internal/timers:541:7)

Node.js v24.15.0
 FAIL  src/components/KeyboardAwareScrollView/__tests__/selectionOrder.spec.tsx
  ● Test suite failed to run

    Jest worker encountered 4 child process exceptions, exceeding retry limit

      at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:181:21)

It happens because KeyboardAwareScrollView has async operations inside useEffect and sometimes we may end test earlier than operation completes.

In this PR I added act + microtask await to avoid those errors.

📢 Changelog

JS

  • wait for end of render before running a test;

🤔 How Has This Been Tested?

Tested locally via yarn test src --coverage.

📸 Screenshots (if appropriate):

Before After
image image

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko self-assigned this Aug 3, 2026
@kirillzyusko kirillzyusko added tests You added or changed unit tests KeyboardAwareScrollView 📜 Anything related to KeyboardAwareScrollView component labels Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

📊 Package size report

Current size Target Size Difference
333861 bytes 333861 bytes 0 bytes 📉

@kirillzyusko
kirillzyusko marked this pull request as ready for review August 3, 2026 13:21
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

LGTM

@kirillzyusko
kirillzyusko merged commit 7de6ea9 into main Aug 4, 2026
17 checks passed
@kirillzyusko
kirillzyusko deleted the fix/stabilize-unit-tests branch August 4, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

KeyboardAwareScrollView 📜 Anything related to KeyboardAwareScrollView component tests You added or changed unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant