npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ek-test-utils

v1.3.0

Published

Zero-config React testing utilities.

Downloads

60

Readme

ek-test-utils

Zero-config, frictionless React testing utilities. Focuses on developer experience by eliminating boilerplate and providing essential mocks out of the box.

Downloads npm version License: MIT

ek-test-utils solves the "configuration fatigue" in React testing. It wraps standard testing libraries and provides ready-to-use mocks for Next.js and browser APIs, letting you focus on writing tests instead of setting them up.


Features

  • Zero Config: Pre-configured render and renderHook with automatic provider wrapping.
  • Next.js Full Suite: Built-in App Router mocks (useRouter) AND Server Component mocks (cookies, headers, next/image).
  • Advanced Browser Mocks: Instantly mock window.matchMedia, IntersectionObserver, ResizeObserver, and navigator.clipboard.
  • Storage Management: Built-in, leak-free localStorage and sessionStorage mock managers.
  • All-in-One: Re-exports everything from @testing-library/react and @testing-library/user-event.
  • Type Safe: Full TypeScript support.

Installation

npm install -D ek-test-utils
# or
yarn add -D ek-test-utils
# or
pnpm add -D ek-test-utils

Usage

1. The Basics (Drop-in Replacement)

Instead of importing from multiple testing libraries, import everything directly from ek-test-utils. Our custom render automatically wraps your components with necessary providers.

import { render, screen, userEvent } from 'ek-test-utils';
import { MyButton } from './MyButton';

test('renders and clicks button', async () => {
  render(<MyButton />);
  
  const button = screen.getByRole('button', { name: /click me/i });
  await userEvent.click(button);
  
  expect(screen.getByText(/clicked/i)).toBeInTheDocument();
});

2. Testing Hooks

Easily test your custom React hooks without needing to create dummy components.

import { renderHook } from 'ek-test-utils';
import { useCounter } from './useCounter';

test('increments counter', () => {
  const { result } = renderHook(() => useCounter());
  
  // result.current.count
});

3. Next.js App Router & Server Mocks

Testing Next.js 13+ components often fails due to missing router contexts or server-only APIs. Use our built-in mocks to bypass these errors effortlessly.

import { mockNextNavigation, mockNextHeaders, mockNextImage } from 'ek-test-utils';

// Mock Navigation (App Router)
vi.mock('next/navigation', () => mockNextNavigation());

// Mock Headers & Cookies (Server Components)
vi.mock('next/headers', () => mockNextHeaders());

// Mock next/image to behave like a standard <img> tag
vi.mock('next/image', () => mockNextImage());

(Note: Use jest.mock() instead of vi.mock() if you are using Jest).

4. Browser API Mocks

Prevent browser-specific errors when testing responsive components, drag-and-drop interfaces, or copy-to-clipboard functionalities.

import { 
  setupMatchMediaMock, 
  setupIntersectionObserverMock,
  setupResizeObserverMock,
  setupClipboardMock
} from 'ek-test-utils';

// Run before your tests
beforeAll(() => {
  setupMatchMediaMock();
  setupIntersectionObserverMock();
  setupResizeObserverMock();
  setupClipboardMock();
});

5. Storage Mocks

Testing localStorage or sessionStorage can cause data leaks between tests. Use our setup function to create a clean, isolated storage environment.

import { setupStorageMocks } from 'ek-test-utils';

beforeEach(() => {
  // Cleans and isolates storage for each test
  setupStorageMocks();
});

📄 License

MIT © Ender


Contributing

Contributions, issues and feature requests are welcome!


⭐ Show your support

Give a ⭐️ if this project helped you!