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

rtk-mock-store

v1.0.0

Published

Modern redux store jest mock helper function for testing reducers using @reduxjs/toolkit slices.

Downloads

15

Readme

rtk-mock-store build-workflow check-code-coverage

Modern redux store jest mock helper function for testing reducers using @reduxjs/toolkit slices.

Installation

To install the rtk-mock-store package, use the following command:

npm install rtk-mock-store

Examples

API Documentation

createMockStore

Creates a mock store for testing redux actions and reducers using redux-toolkit. It can be used to test a single reducer in isolation or multiple reducers together.

Type Parameters
  • MockRootState: The root state of the mock store.
Parameters
  • reducerToTest: The reducer to test (key of MockRootState).
  • reducers: All reducers in the store (ReducersMapObject).
  • initialRootState: The initial state of the store (MockRootState).
Returns
  • RTKMockStore<MockRootState>: The mock store instance.
Example
// reducer.test.ts
import createMockStore from 'rtk-mock-store';
import { INITIAL_STATE, reducer, testAction } from './reducer';

const mockStore = createMockStore(
  'reducerToTest',
  { reducerToTest: reducer },
  { reducerToTest: INITIAL_STATE }
);

describe('reducerToTest', () => {
  afterEach(() => {
    mockStore.reset();
  });

  it('should have initial state', () => {
    expect(mockStore.getReducerState()).toEqual({ test: false });
  });

  it('should set test to true', () => {
    mockStore.dispatch(testAction());
    expect(mockStore.dispatch.mock.calls[0][0].type).toEqual('reducerToTest/TEST_ACTION');
    expect(mockStore.getReducerState()).toEqual({ test: true });
  });
});

RTKMockStore Properties

|Property|Type|Comments| |-|-|-| |rootStateSnapshots|Record<Action['type'], MockRootState>[]|The snapshots of the root state of the mock store.| |rootState|MockRootState|The root state of the mock store.| |extraArgument|object|The extra argument of the mock store.| |getRootState|() => MockRootState|Returns the root state of the mock store.| |getReducerState|() => MockRootState[keyof MockRootState]|Returns the state of the reducer being tested.| |setRootState|(state: MockRootState) => void|Sets the root state of the mock store.| |setReducerState|(state: MockRootState[keyof MockRootState]) => void|Sets the state of the reducer being tested.| |getRootStateSnapshots|() => Record<Action['type'], MockRootState>[]|Returns the snapshots of the root state of the mock store.| |getRootStateSnapshot|(actionType: Action['type']) => Record<Action['type'], MockRootState> \| undefined|Returns the snapshot of the root state of the mock store for a specific action type.| |getReducerStateSnapshots|() => Record<Action['type'], MockRootState[keyof MockRootState]>[]|Returns the snapshots of the reducer being tested.| |getReducerStateSnapshot|(actionType: Action['type']) => Record<Action['type'], MockRootState[keyof MockRootState]> \| undefined|Returns the snapshot of the reducer being tested for a specific action type.| |printReducerStateSnapshots|() => void|Prints the snapshots of the reducer being tested.| |printRootStateSnapshots|() => void|Prints the snapshots of the root state of the mock store.| |next|(action: Action) => void|The next middleware function.| |runThunk|(action: ThunkAction<any, MockRootState, any, Action>) => void|Runs a thunk action.| |getState|() => MockRootState|Returns the root state of the mock store.| |dispatch|(action: Action) => void|Dispatches an action to the mock store.| |reset|() => void|Resets the mock store state to intialRootState.|

Contribution

If you want to contribute to this project, send a PR directly instead of creating an issue.