From aa73ee9c2aacdf7af8ae244fde961863bf72e170 Mon Sep 17 00:00:00 2001 From: Michael Peyper Date: Tue, 19 Jan 2021 06:14:28 +1100 Subject: [PATCH] fix: improve error message when auto-detection fails to mention bundlers Fixes #544 --- docs/installation.md | 4 ++-- src/__tests__/defaultRenderer.test.ts | 2 +- src/pure.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index 33f17f25..942178cd 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -57,8 +57,8 @@ The standard import looks like: import { renderHook } from '@testing-library/react-hooks' ``` -> Note: The auto detection function may not work if tests are bundles before execution (e.g. to be -> run in a browser) +> Note: The auto detection function may not work if tests are being bundled (e.g. to be run in a +> browser) ### Act diff --git a/src/__tests__/defaultRenderer.test.ts b/src/__tests__/defaultRenderer.test.ts index 0352813d..5c633a5e 100644 --- a/src/__tests__/defaultRenderer.test.ts +++ b/src/__tests__/defaultRenderer.test.ts @@ -34,7 +34,7 @@ describe('default renderer', () => { }) const expectedMessage = - "Could not auto-detect a React renderer. Are you sure you've installed one of the following\n - react-dom\n - react-test-renderer" + "Could not auto-detect a React renderer. Are you sure you've installed one of the following:\n - react-dom\n - react-test-renderer\nIf you are using a bundler, please update you imports to use a specific renderer. For instructions see: https://react-hooks-testing-library.com/installation#being-specific" expect(() => require('..')).toThrowError(new Error(expectedMessage)) }) diff --git a/src/pure.ts b/src/pure.ts index 699c7c10..8146b1b6 100644 --- a/src/pure.ts +++ b/src/pure.ts @@ -27,7 +27,7 @@ function getRenderer() { .join('\n') throw new Error( - `Could not auto-detect a React renderer. Are you sure you've installed one of the following\n${options}` + `Could not auto-detect a React renderer. Are you sure you've installed one of the following:\n${options}\nIf you are using a bundler, please update you imports to use a specific renderer. For instructions see: https://react-hooks-testing-library.com/installation#being-specific` ) } }