Skip to content

jabro86/redux-testing-library

Repository files navigation

redux-testing-library

Simple and maintainable tests for your react/redux application inspired by react-testing-library.

Build Status Coverage Status code style: prettier License: MIT

Features

  • simple data-driven integration tests
  • dispatch actions, wait for store changes and assert the result
  • do not test implementation details: just rely on your actions and selectors
  • it also covers all middleware functionalities, e.g. async code via redux-saga
  • includes the full power of react-testing-library (no other dependencies)

How to use?

import * as React from "react";
import { render } from "redux-testing-library";

import { TodoApp, TodoActions, TodoSelectors } from "./example";

describe("when addTodo action is dispatched", () => {
  it("adds todo item to the store", async () => {
    const { store, waitForStoreChange } = render(<TodoApp.UI />, TodoApp.store);

    store.dispatch(TodoActions.addTodo("Test your application"));

    await waitForStoreChange(state => {
      const todos = TodoSelectors.getTodos(state);
      expect(todos[0].text).toBe("Test your application");
    });
  });
});