Description
react-hooks-testing-library
version: 5.0.0react-test-renderer
version: 16.14.0react
version: 16.14.0node
version: 10.xnpm
(oryarn
) version: yarn 1.22
Relevant code or config:
import { renderHook } from '@testing-library/react-hooks';
What you did:
Use @testing-library/react-hooks
in code bundled for the browser with webpack.
What happened:
Uncaught Error: Could not auto-detect a React renderer. Are you sure you've installed one of the following
- react-dom
- react-test-renderer
at webpack:///node_modules/@testing-library/react-hooks/lib/pure.js:58:1 <- test/karma.tests.js:16233:5
Full CI error log: https://app.circleci.com/pipelines/github/mui-org/material-ui/36491/workflows/08a2e3dd-21aa-474f-86cf-6458c9dd552e/jobs/217134/steps
Bundle: https://circle-production-customer-artifacts.s3.amazonaws.com/picard/53f31667f7d05ec7d09d22f4/6004879acb28353dcdb73883-0-build/artifacts/artifact-file/test/karma.tests.js?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210117T203410Z&X-Amz-SignedHeaders=host&X-Amz-Expires=60&X-Amz-Credential=AKIAJR3Q6CR467H7Z55A%2F20210117%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=c5763f2e26dc5cd18e317195fc40c5fe06f8e96a1d2b2c842a5edf5e393ec2ee
Reproduction:
https://github.com/eps1lon/testing-libray-hooks-dynamic-require
Problem description:
We want to run tests in a real browser i.e. an environment where React can run (using karma-mocha). Some of those tests uses @testing-library/react-hooks
.
Suggested solution:
Remove dynamic require(variable)
. require
can only be bundled by webpack if called with a string literal.