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

zustand-jest-utils

v0.1.0

Published

Zustand Jest Utils: A set of utility functions designed to simplify testing Zustand stores in your React applications with Jest, providing functions for creating mock stores, replacing stores, rendering components with custom stores, and resetting stores.

Readme

zustand-jest-utils

zustand-jest-utils is a set of utility functions designed to simplify testing custom stores in your React applications. The package is compatible with Zustand and provides functions for creating mock stores, replacing stores, rendering components with custom stores, and resetting stores.

Installation

Install the package using npm:

npm install zustand-jest-utils

Usage

First, import the utility functions from the package:

import {
  createTestStore,
  createMockStore,
  replaceStore,
  renderWithStore,
  resetStore,
} from 'zustand-jest-utils';

Creating a Test Store

Use the createTestStore function to create a custom store with an initial state and custom actions:

const initialState = { count: 0 };
const customActions = (set) => ({
  increment: () => set((state) => ({ count: state.count + 1 })),
});

const store = createTestStore(initialState, customActions);

Creating a Mock Store

Use the createMockStore function to create a mock store with an initial state, custom actions, and optional action overrides:

const initialState = { count: 0 };
const customActions = (set) => ({
  increment: () => set((state) => ({ count: state.count + 1 })),
});

const overrides = { increment: () => {} };

const mockStore = createMockStore(initialState, customActions, overrides);

Replacing a Store

Use the replaceStore function to replace an old store with a new store:

const newStore = replaceStore(oldStore, mockStore);

Rendering a Component with a Custom Store

Use the renderWithStore function to render a component with a custom store. This function internally uses the React Testing Library's render method:

import { MyComponent } from './MyComponent';

const { getByText } = renderWithStore(<MyComponent />, store);

Resetting a Store

Use the resetStore function to reset a store to its initial state:

resetStore(store, initialState);

Example

Here's an example of how to use React Testing Store Utils in a test:

import {
  createMockStore,
  renderWithStore,
} from 'zustand-jest-utils';

import { fireEvent, screen } from '@testing-library/react';
import MyComponent from './MyComponent';

test('MyComponent should update the count on button click', () => {
  const initialState = { count: 0 };
  const customActions = (set) => ({
    increment: () => set((state) => ({ count: state.count + 1 })),
  });

  const store = createMockStore(initialState, customActions);
  renderWithStore(<MyComponent />, store);

  fireEvent.click(screen.getByText('Increment'));

  expect(store.getState().count).toBe(1);
});

License

zustand-jest-utils is released under the MIT License.

Contributing

Feel free to open issues or submit pull requests to help improve this package. Your contributions are always welcome!