Skip to content

Commit

Permalink
Merge pull request #20 from msmith-techempower/test-async-await
Browse files Browse the repository at this point in the history
Adds compound async action test
  • Loading branch information
msmith-techempower committed May 14, 2019
2 parents a7fd424 + f46f70b commit a42ecdb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/examples/counter/Counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export default function Counter() {
/>
<button className="removeState" onClick={() => actions.removeState()} />
<button className="asyncFunc" onClick={actions.asyncFunc} />
<button
className="compoundAsyncFunc"
onClick={async () => {
// Should set `state.count` = 256
await actions.asyncFunc();
// Should set `state.count` = 257
actions.increment();
}}
/>
<input className="googleStatus" value={state.status} />
<button className="fetchGoogle" onClick={actions.fetchGoogle} />
</div>
Expand Down
14 changes: 14 additions & 0 deletions src/tests/counter/Counter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ it("can asyncFunc", async () => {
});
});

it("can do compound async actions", async () => {
const counter = TestRenderer.create(<Counter />);
const val = counter.root.findByProps({ className: "val" });
const button = counter.root.findByProps({ className: "compoundAsyncFunc" });

await act(async () => {
expect(val.props.value).toBe(0);

await button.props.onClick();

expect(val.props.value).toBe(257);
});
});

it("can fetchGoogle", async () => {
const counter = TestRenderer.create(<Counter />);
const val = counter.root.findByProps({ className: "googleStatus" });
Expand Down

0 comments on commit a42ecdb

Please sign in to comment.