Skip to content

Commit f014c98

Browse files
authored
Merge pull request #25 from nbrady-techempower/update-tests
Most tests don't need async act anymore
2 parents 16e61f7 + 2514def commit f014c98

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

src/tests/counter-provider/CounterProvider.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ it("shares state among sibling context consumers", async () => {
5858
.findByType(CounterChildTwo)
5959
.findByProps({ className: "dec" });
6060

61-
await act(async () => {
61+
act(() => {
6262
expect(val.props.value).toBe(0);
6363
expect(val2.props.value).toBe(0);
6464

65-
await buttonOneInc.props.onClick();
65+
buttonOneInc.props.onClick();
6666

6767
expect(val.props.value).toBe(1);
6868
expect(val2.props.value).toBe(1);
6969

70-
await buttonTwoDec.props.onClick();
70+
buttonTwoDec.props.onClick();
7171

7272
expect(val.props.value).toBe(0);
7373
expect(val2.props.value).toBe(0);
@@ -108,24 +108,24 @@ it("shares state among sibling and children context consumers", async () => {
108108
.findByType(CounterGrandchild)
109109
.findByProps({ className: "inc" });
110110

111-
await act(async () => {
111+
act(() => {
112112
expect(val.props.value).toBe(0);
113113
expect(val2.props.value).toBe(0);
114114
expect(gval.props.value).toBe(0);
115115

116-
await buttonOneInc.props.onClick();
116+
buttonOneInc.props.onClick();
117117

118118
expect(val.props.value).toBe(1);
119119
expect(val2.props.value).toBe(1);
120120
expect(gval.props.value).toBe(1);
121121

122-
await buttonTwoDec.props.onClick();
122+
buttonTwoDec.props.onClick();
123123

124124
expect(val.props.value).toBe(0);
125125
expect(val2.props.value).toBe(0);
126126
expect(gval.props.value).toBe(0);
127127

128-
await gbutton.props.onClick();
128+
gbutton.props.onClick();
129129

130130
expect(val.props.value).toBe(1);
131131
expect(val2.props.value).toBe(1);

src/tests/counter/Counter.spec.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,128 +17,128 @@ it("starts with initial state", () => {
1717
expect(val.props.value).toBe(0);
1818
});
1919

20-
it("can increment", async () => {
20+
it("can increment", () => {
2121
const counter = TestRenderer.create(<Counter />);
2222
const val = counter.root.findByProps({ className: "val" });
2323
const button = counter.root.findByProps({ className: "inc" });
2424

25-
await act(async () => {
25+
act(() => {
2626
expect(val.props.value).toBe(0);
2727

28-
await button.props.onClick();
28+
button.props.onClick();
2929

3030
expect(val.props.value).toBe(1);
3131

32-
await button.props.onClick();
32+
button.props.onClick();
3333

3434
expect(val.props.value).toBe(2);
3535
});
3636
});
3737

38-
it("can decrement", async () => {
38+
it("can decrement", () => {
3939
const counter = TestRenderer.create(<Counter />);
4040
const val = counter.root.findByProps({ className: "val" });
4141
const button = counter.root.findByProps({ className: "dec" });
4242

43-
await act(async () => {
43+
act(() => {
4444
expect(val.props.value).toBe(0);
4545

46-
await button.props.onClick();
46+
button.props.onClick();
4747

4848
expect(val.props.value).toBe(-1);
4949

50-
await button.props.onClick();
50+
button.props.onClick();
5151

5252
expect(val.props.value).toBe(-2);
5353
});
5454
});
5555

56-
it("can add5", async () => {
56+
it("can add5", () => {
5757
const counter = TestRenderer.create(<Counter />);
5858
const val = counter.root.findByProps({ className: "val" });
5959
const button = counter.root.findByProps({ className: "add5" });
6060

61-
await act(async () => {
61+
act(() => {
6262
expect(val.props.value).toBe(0);
6363

64-
await button.props.onClick();
64+
button.props.onClick();
6565

6666
expect(val.props.value).toBe(5);
6767

68-
await button.props.onClick();
68+
button.props.onClick();
6969

7070
expect(val.props.value).toBe(10);
7171
});
7272
});
7373

74-
it("can set", async () => {
74+
it("can set", () => {
7575
const counter = TestRenderer.create(<Counter />);
7676
const val = counter.root.findByProps({ className: "val" });
7777
const button = counter.root.findByProps({ className: "set" });
7878

79-
await act(async () => {
79+
act(() => {
8080
expect(val.props.value).toBe(0);
8181

82-
await button.props.onClick();
82+
button.props.onClick();
8383

8484
expect(val.props.value).toBe(137);
8585

86-
await button.props.onClick();
86+
button.props.onClick();
8787

8888
expect(val.props.value).toBe(137);
8989
});
9090
});
9191

92-
it("can addSum", async () => {
92+
it("can addSum", () => {
9393
const counter = TestRenderer.create(<Counter />);
9494
const val = counter.root.findByProps({ className: "val" });
9595
const button = counter.root.findByProps({ className: "addSum" });
9696

97-
await act(async () => {
97+
act(() => {
9898
expect(val.props.value).toBe(0);
9999

100-
await button.props.onClick();
100+
button.props.onClick();
101101

102102
expect(val.props.value).toBe(7);
103103

104-
await button.props.onClick();
104+
button.props.onClick();
105105

106106
expect(val.props.value).toBe(14);
107107
});
108108
});
109109

110-
it("can addNewState", async () => {
110+
it("can addNewState", () => {
111111
const counter = TestRenderer.create(<Counter />);
112112
const val = counter.root.findByProps({ className: "val" });
113113
const newState = counter.root.findByProps({ className: "newState" });
114114
const button = counter.root.findByProps({ className: "addNewState" });
115115

116-
await act(async () => {
116+
act(() => {
117117
expect(newState.props.value).toBe(undefined);
118118

119-
await button.props.onClick();
119+
button.props.onClick();
120120

121121
expect(newState.props.value).toBe("Hello");
122122
expect(val.props.value).toBe(0);
123123
});
124124
});
125125

126-
it("can removeState", async () => {
126+
it("can removeState", () => {
127127
const counter = TestRenderer.create(<Counter />);
128128
const val = counter.root.findByProps({ className: "val" });
129129
const newState = counter.root.findByProps({ className: "newState" });
130130
const button = counter.root.findByProps({ className: "addNewState" });
131131
const removeButton = counter.root.findByProps({ className: "removeState" });
132132

133-
await act(async () => {
133+
act(() => {
134134
expect(newState.props.value).toBe(undefined);
135135

136-
await button.props.onClick();
136+
button.props.onClick();
137137

138138
expect(newState.props.value).toBe("Hello");
139139
expect(val.props.value).toBe(0);
140140

141-
await removeButton.props.onClick();
141+
removeButton.props.onClick();
142142

143143
expect(val.props.value).toBe(undefined);
144144
});

src/tests/simple-counter/SimpleCounter.spec.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,73 +17,73 @@ it("starts with initial state", () => {
1717
expect(val.props.value).toBe(0);
1818
});
1919

20-
it("can increment", async () => {
20+
it("can increment", () => {
2121
const counter = TestRenderer.create(<SimpleCounter />);
2222
const val = counter.root.findByProps({ className: "val" });
2323
const button = counter.root.findByProps({ className: "inc" });
2424

25-
await act(async () => {
25+
act(() => {
2626
expect(val.props.value).toBe(0);
2727

28-
await button.props.onClick();
28+
button.props.onClick();
2929

3030
expect(val.props.value).toBe(1);
3131

32-
await button.props.onClick();
32+
button.props.onClick();
3333

3434
expect(val.props.value).toBe(2);
3535
});
3636
});
3737

38-
it("can decrement", async () => {
38+
it("can decrement", () => {
3939
const counter = TestRenderer.create(<SimpleCounter />);
4040
const val = counter.root.findByProps({ className: "val" });
4141
const button = counter.root.findByProps({ className: "dec" });
4242

43-
await act(async () => {
43+
act(() => {
4444
expect(val.props.value).toBe(0);
4545

46-
await button.props.onClick();
46+
button.props.onClick();
4747

4848
expect(val.props.value).toBe(-1);
4949

50-
await button.props.onClick();
50+
button.props.onClick();
5151

5252
expect(val.props.value).toBe(-2);
5353
});
5454
});
5555

56-
it("can add5", async () => {
56+
it("can add5", () => {
5757
const counter = TestRenderer.create(<SimpleCounter />);
5858
const val = counter.root.findByProps({ className: "val" });
5959
const button = counter.root.findByProps({ className: "add5" });
6060

61-
await act(async () => {
61+
act(() => {
6262
expect(val.props.value).toBe(0);
6363

64-
await button.props.onClick();
64+
button.props.onClick();
6565

6666
expect(val.props.value).toBe(5);
6767

68-
await button.props.onClick();
68+
button.props.onClick();
6969

7070
expect(val.props.value).toBe(10);
7171
});
7272
});
7373

74-
it("can sub2", async () => {
74+
it("can sub2", () => {
7575
const counter = TestRenderer.create(<SimpleCounter />);
7676
const val = counter.root.findByProps({ className: "val" });
7777
const button = counter.root.findByProps({ className: "sub2" });
7878

79-
await act(async () => {
79+
act(() => {
8080
expect(val.props.value).toBe(0);
8181

82-
await button.props.onClick();
82+
button.props.onClick();
8383

8484
expect(val.props.value).toBe(-2);
8585

86-
await button.props.onClick();
86+
button.props.onClick();
8787

8888
expect(val.props.value).toBe(-4);
8989
});

0 commit comments

Comments
 (0)