|
1 | 1 | # redux-testing-library
|
2 | 2 |
|
| 3 | +Simple and maintainable tests for your react/redux application inspired by [react-testing-library](https://testing-library.com/). |
| 4 | + |
3 | 5 | [](https://travis-ci.org/jabro86/redux-testing-library)
|
4 | 6 | [](https://coveralls.io/github/jabro86/redux-testing-library?branch=master)
|
5 | 7 | [](https://github.com/prettier/prettier)
|
6 | 8 | [](https://opensource.org/licenses/MIT)
|
7 | 9 |
|
8 |
| -Simple and maintainable tests for your react/redux application inspired by [react-testing-library](https://testing-library.com/). |
| 10 | +## Features |
9 | 11 |
|
10 |
| -- write simple and reliable integration tests |
| 12 | +- simple data-driven integration tests |
11 | 13 | - dispatch actions, wait for store changes and assert the result
|
12 |
| -- do not test implementation details: just rely on actions and selectors |
| 14 | +- do not test implementation details: just rely on your actions and selectors |
| 15 | +- it also covers all middleware functionalities, e.g. async code via redux-saga |
13 | 16 | - includes the full power of react-testing-library (no other dependencies)
|
| 17 | + |
| 18 | +## How to use? |
| 19 | + |
| 20 | +```typescript |
| 21 | +import * as React from "react"; |
| 22 | +import { render } from "redux-testing-library"; |
| 23 | + |
| 24 | +import { TodoApp, TodoActions, TodoSelectors } from "./example"; |
| 25 | + |
| 26 | +describe("todo app", () => { |
| 27 | + describe("when addTodo action is dispatched with a given text as payload", () => { |
| 28 | + it("adds a todo item with the given text to the store", async () => { |
| 29 | + const { store, waitForStoreChange } = render(<TodoApp.UI />, TodoApp.store); |
| 30 | + |
| 31 | + store.dispatch(TodoActions.addTodo("Do homework!")); |
| 32 | + |
| 33 | + await waitForStoreChange(state => { |
| 34 | + expect(TodoSelectors.getTodos(state)).toStrictEqual([ |
| 35 | + { id: 0, completed: false, text: "Do homework!" } |
| 36 | + ]); |
| 37 | + }); |
| 38 | + }); |
| 39 | + }); |
| 40 | +}); |
| 41 | +``` |
0 commit comments