Skip to content

Commit

Permalink
fix(readme): simplify the example
Browse files Browse the repository at this point in the history
  • Loading branch information
jabro86 committed May 27, 2019
1 parent 1451672 commit efe7602
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ import { render } from "redux-testing-library";

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

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

store.dispatch(TodoActions.addTodo("Do homework!"));

await waitForStoreChange(state => {
expect(TodoSelectors.getTodos(state)).toStrictEqual([
{ id: 0, completed: false, text: "Do homework!" }
]);
});
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");
});
});
});
Expand Down
17 changes: 7 additions & 10 deletions test/redux-testing-library.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ import * as React from "react";
import { render } from "../src/redux-testing-library";
import { TodoApp, TodoActions, TodoSelectors } from "./example";

describe("todo app", () => {
describe("when addTodo action is dispatched with a given text as payload", () => {
it("adds a todo item with the given text to the store", async () => {
const { store, waitForStoreChange } = render(<TodoApp.UI />, TodoApp.store);
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("Do homework!"));
store.dispatch(TodoActions.addTodo("Test your application"));

await waitForStoreChange(state => {
expect(TodoSelectors.getTodos(state)).toStrictEqual([
{ id: 0, completed: false, text: "Do homework!" }
]);
});
await waitForStoreChange(state => {
const todos = TodoSelectors.getTodos(state);
expect(todos[0].text).toBe("Test your application");
});
});
});

0 comments on commit efe7602

Please sign in to comment.