Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@ttoss/test-utils

Package Overview
Dependencies
Maintainers
2
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ttoss/test-utils

This package provides a number of utilities and re-exports for testing using Jest, React Testing Library, and Relay.

Source
npmnpm
Version
4.2.16
Version published
Weekly downloads
782
37.68%
Maintainers
2
Weekly downloads
 
Created
Source

@ttoss/test-utils

Testing utilities for Jest with React Testing Library, user events, Relay helpers, faker, and optional ESM transform helpers.

Installation

pnpm add -D @ttoss/test-utils

Entry Points

ImportWhat it gives youSide effects
@ttoss/test-utils/reactrender, renderHook, userEvent, emotion matchers, jest-dom matchers, ResizeObserver polyfill, snapshot serializerYes (extends expect, polyfills)
@ttoss/test-utils/fakerfaker ESM re-exportNo
@ttoss/test-utils/relayRelay test utilitiesNo
@ttoss/test-utilsUtility: 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.

Quick Start

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);
});

Global Wrapper

import { setOptions } from '@ttoss/test-utils/react';
import AllProviders from './src/AllProviders';

setOptions({ wrapper: AllProviders });
export default {
  setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
  testEnvironment: 'jsdom',
};

Relay Testing

import {
  createMockEnvironment,
  MockPayloadGenerator,
} from '@ttoss/test-utils/relay';

const environment = createMockEnvironment();

More patterns: Testing Relay Components

Fake Data

import { faker } from '@ttoss/test-utils/faker';

const testUser = {
  name: faker.person.fullName(),
  email: faker.internet.email(),
};

ESM Transform Helper (Jest)

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.

Features Summary

  • React Testing Library (render, renderHook, queries)
  • User events (userEvent)
  • jest-dom matchers
  • Emotion matchers + snapshot serializer
  • ResizeObserver polyfill
  • Relay test utilities
  • Faker ESM helper
  • PNPM-aware ESM transform pattern generator

FAQ

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.

Minimal Config Only (No side effects)

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.

Keywords

Jest

FAQs

Package last updated on 05 Jun 2026

Did you know?

Socket

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.

Install

Related posts