Registry / testing / preact-test-utils

preact-test-utils

JSON →
library0.1.4jsnpmunverified

This package, `preact-test-utils` version 0.1.4, served as an early compatibility layer for testing Preact components by allowing users to alias `react-addons-test-utils` in their build configuration (e.g., Webpack). Its primary goal was to enable existing React testing setups that relied on `react-addons-test-utils` to function with Preact without significant code changes. However, `react-addons-test-utils` itself was officially deprecated by React in version 15.5.0 (around 2017) and its functionalities were migrated to `react-dom/test-utils` and `react-test-renderer/shallow`. Consequently, `preact-test-utils` is now obsolete and effectively abandoned. Modern Preact testing relies on `@testing-library/preact` which wraps the official `preact/test-utils` module provided by the Preact core, offering a more robust and idiomatic approach to component testing.

npm install preact-test-utils
INSTALL
IMPORT
SIG · PREACT-TEST-UTILS
P
preact-test-utils
testingjavascriptv0.1.4
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TestUtils
✓ import TestUtils from 'react-addons-test-utils';
✗ import { TestUtils } from 'preact-test-utils';
This package primarily functioned as a Webpack alias for `react-addons-test-utils`. Direct imports from `preact-test-utils` itself were not the intended usage. The aliased `react-addons-test-utils` would then expose methods like `renderIntoDocument`, `Simulate`, etc.
shallowRenderer
✓ import ShallowRenderer from 'react-addons-test-utils/shallow';
For shallow rendering, `react-addons-test-utils` had a separate entry point. This package would have redirected this as well. Note that `shallowRenderer` was later moved to `react-test-renderer/shallow` in React.

Demonstrates the required Webpack alias configuration for `preact-test-utils` and a conceptual test using the emulated `react-addons-test-utils` API. This approach is highly outdated.

/* webpack.config.js (conceptual, highly outdated) */ module.exports = { // ... other webpack config resolve: { alias: { 'react-addons-test-utils': 'preact-test-utils' } } }; /* Example test file (conceptual usage with the alias) */ import { h } from 'preact'; import { render } from 'preact'; // Assuming the alias is set up in webpack, this would resolve to preact-test-utils import TestUtils from 'react-addons-test-utils'; function MyComponent({ name }) { return <div>Hello, {name}</div>; } describe('MyComponent', () => { test('should render correctly', () => { const node = document.createElement('div'); // Using TestUtils from the aliased package TestUtils.renderIntoDocument(<MyComponent name="World" />, node); expect(node.textContent).toBe('Hello, World'); // Modern approach with @testing-library/preact: // const { getByText } = render(<MyComponent name="World" />); // expect(getByText('Hello, World')).toBeInTheDocument(); }); });
Debug
Known issues
breakingThe underlying `react-addons-test-utils` package, which `preact-test-utils` aimed to mimic, was deprecated in React 15.5.0. Its functionalities were moved to `react-dom/test-utils` and `react-test-renderer/shallow`. Using this alias will likely lead to compatibility issues or reliance on deprecated APIs.
fix
Migrate your testing setup to `@testing-library/preact` which is the current recommended approach for testing Preact components. This library wraps `preact/test-utils` and provides a user-centric API.
affects: >=0.1.4
gotchaThis package is extremely old (version 0.1.4) and has not been maintained for many years. It predates significant advancements in both Preact and React testing practices.
fix
Do not use this package. Adopt `@testing-library/preact` for all new and existing Preact component tests.
affects: >=0.1.4
gotchaThe provided README explicitly shows a Webpack alias configuration. This package does not provide direct exports under its own name for testing utilities, but rather acts as a redirection target for `react-addons-test-utils`.
fix
Understand that usage involves configuring a module alias. However, this is not a recommended solution for modern Preact development.
affects: >=0.1.4
Errors
Common errors & fixes
Cannot read property 'renderIntoDocument' of undefined
The Webpack alias for `react-addons-test-utils` might not be correctly configured or the aliased `preact-test-utils` package is not correctly mocking the expected API.
fix
Ensure your Webpack configuration correctly aliases `react-addons-test-utils` to `preact-test-utils`. However, it is strongly advised to migrate to `@testing-library/preact` instead of troubleshooting this legacy setup.
Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.
This warning indicates that even with the alias, the underlying React/Preact environment or some other dependency is detecting the usage of the deprecated `react-addons-test-utils` pattern.
fix
This warning is inherent to using a deprecated API. The only real fix is to stop using `react-addons-test-utils` and by extension `preact-test-utils`, and instead adopt modern Preact testing solutions like `@testing-library/preact`.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
preact-test-utils — npm install preact-test-utils · libregistry