Skip to content

Commit 1451672

Browse files
committed
fix(readme): update readme file with how to use section
1 parent 624089c commit 1451672

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

README.md

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
11
# redux-testing-library
22

3+
Simple and maintainable tests for your react/redux application inspired by [react-testing-library](https://testing-library.com/).
4+
35
[![Build Status](https://travis-ci.org/jabro86/redux-testing-library.svg?branch=master)](https://travis-ci.org/jabro86/redux-testing-library)
46
[![Coverage Status](https://coveralls.io/repos/github/jabro86/redux-testing-library/badge.svg?branch=master)](https://coveralls.io/github/jabro86/redux-testing-library?branch=master)
57
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
68
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
79

8-
Simple and maintainable tests for your react/redux application inspired by [react-testing-library](https://testing-library.com/).
10+
## Features
911

10-
- write simple and reliable integration tests
12+
- simple data-driven integration tests
1113
- 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
1316
- 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+
```

test/example/index.tsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import rootReducer from "./reducers";
77
import * as TodoActions from "./actions";
88
import * as TodoSelectors from "./selectors";
99

10-
export const store = createStore(rootReducer);
11-
export const TodoApp: React.ComponentType = () => (
12-
<Provider store={store}>
13-
<App />
14-
</Provider>
15-
);
10+
export const TodoApp = {
11+
store: createStore(rootReducer),
12+
UI: () => (
13+
<Provider store={TodoApp.store}>
14+
<App />
15+
</Provider>
16+
)
17+
};
1618

1719
export { TodoActions, TodoSelectors };

test/redux-testing-library.test.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import * as React from "react";
22

33
import { render } from "../src/redux-testing-library";
4-
import { TodoApp, store, TodoActions, TodoSelectors } from "./example";
4+
import { TodoApp, TodoActions, TodoSelectors } from "./example";
55

66
describe("todo app", () => {
77
describe("when addTodo action is dispatched with a given text as payload", () => {
88
it("adds a todo item with the given text to the store", async () => {
9-
const {
10-
store: { dispatch },
11-
waitForStoreChange
12-
} = render(<TodoApp />, store);
9+
const { store, waitForStoreChange } = render(<TodoApp.UI />, TodoApp.store);
1310

14-
dispatch(TodoActions.addTodo("Do homework!"));
11+
store.dispatch(TodoActions.addTodo("Do homework!"));
1512

1613
await waitForStoreChange(state => {
1714
expect(TodoSelectors.getTodos(state)).toStrictEqual([

0 commit comments

Comments
 (0)