
Company News
Andrew Becherer Joins Socket as Chief Information Security Officer
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.
@ttoss/test-utils
Advanced tools
This package provides a number of utilities and re-exports for testing using Jest, React Testing Library, and Relay.
Testing utilities for Jest with React Testing Library, user events, Relay helpers, faker, and optional ESM transform helpers.
pnpm add -D @ttoss/test-utils
| Import | What it gives you | Side effects |
|---|---|---|
@ttoss/test-utils/react | render, renderHook, userEvent, emotion matchers, jest-dom matchers, ResizeObserver polyfill, snapshot serializer | Yes (extends expect, polyfills) |
@ttoss/test-utils/faker | faker ESM re-export | No |
@ttoss/test-utils/relay | Relay test utilities | No |
@ttoss/test-utils | Utility: getTransformIgnorePatterns (ESM Jest helper) | No |
Future: a lean version without side effects can be added as a distinct entry (e.g. react-core)—current react entry already includes the jsdom-oriented setup.
import { render, screen, userEvent, renderHook } from '@ttoss/test-utils/react';
test('component', async () => {
const user = userEvent.setup();
render(<Counter />);
await user.click(screen.getByText('Increment'));
expect(screen.getByText('1')).toBeInTheDocument();
});
test('hook', () => {
const { result } = renderHook(() => useCounter());
expect(result.current.count).toBe(0);
});
import { setOptions } from '@ttoss/test-utils/react';
import AllProviders from './src/AllProviders';
setOptions({ wrapper: AllProviders });
export default {
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testEnvironment: 'jsdom',
};
import {
createMockEnvironment,
MockPayloadGenerator,
} from '@ttoss/test-utils/relay';
const environment = createMockEnvironment();
More patterns: Testing Relay Components
import { faker } from '@ttoss/test-utils/faker';
const testUser = {
name: faker.person.fullName(),
email: faker.internet.email(),
};
Use getTransformIgnorePatterns to ensure ESM packages are transformed under pnpm layout.
The following modules are included by default (TTOSS_ESM_MODULES): see the source for the full list.
import { getTransformIgnorePatterns } from '@ttoss/test-utils';
const transformIgnorePatterns = getTransformIgnorePatterns({
esmModules: ['@faker-js/faker'],
});
export default {
testEnvironment: 'jsdom',
transformIgnorePatterns,
};
If you see SyntaxError: Cannot use import statement outside a module, add the module name to esmModules.
render, renderHook, queries)userEvent)Q: Why is getTransformIgnorePatterns separate?
A: It’s a pure configuration helper without runtime side effects; keeping it in the root avoids pulling in DOM matchers unnecessarily.
Q: Do I need to import jest-dom manually?
A: Not when using @ttoss/test-utils/react (it auto-registers).
Q: How do I add another ESM library?
A: Include it in esmModules: getTransformIgnorePatterns({ esmModules: ['@faker-js/faker','some-lib'] }). The built-in TTOSS_ESM_MODULES are always included.
If you ever need a lean setup (no global matchers), you can create your own thin adapter by importing directly from @testing-library/react and @testing-library/user-event. Current package focuses on convenience defaults.
FAQs
This package provides a number of utilities and re-exports for testing using Jest, React Testing Library, and Relay.
We found that @ttoss/test-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.