Skip to content

make usage of jest.mock for react-dom conform to defined behavior

Administrator requested to merge jest-mock-usage into master

Created by: sqs

This helps prepare for using Babel to transpile TypeScript but is good practice regardless.

  • In code_intelligence.test.tsx, the jest.mock('react-dom', ...) was rejected with a fatal error by Babel (in babel-jest) because it referred to an out-of-scope variable (for why it rejects this, see https://github.com/facebook/jest/issues/2567). Also, it was undefined behavior that the jest.mock of react-dom applied to other modules (see "...mocked only for the file that calls jest.mock..." at https://jestjs.io/docs/en/jest-object#jestmockmodulename-factory-options). So, this commit passes the react-dom render function as an argument to the functions under test to make mocking easier and fully explicit without the need for test harness magic.
  • Removes unnecessary mocking of react-dom in text_fields.test.tsx. The mock was never checked.

I encountered these problems while trying out Babel 7 for TypeScript transpilation, but fixing them is good practice regardless.

Merge request reports

Loading