Skip to content

Commit 52266af

Browse files
authored
Remove most React.Uncurried from tests (but keep 1) (#890)
* Remove React.Uncurried * Keep a test with React.Uncurried.useState
1 parent 5cd0660 commit 52266af

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

test/Hooks__test.re

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let store = (initialState: 'a) => {
4949
};
5050
};
5151

52-
module DummyStatefulComponent = {
52+
module DummyStatefulAndUncurriedComponent = {
5353
[@react.component]
5454
let make = (~initialValue=0, ()) => {
5555
let (value, setValue) = React.Uncurried.useState(() => initialValue);
@@ -58,14 +58,23 @@ module DummyStatefulComponent = {
5858
};
5959
};
6060

61+
module DummyStatefulComponent = {
62+
[@react.component]
63+
let make = (~initialValue=0, ()) => {
64+
let (value, setValue) = React.useState(() => initialValue);
65+
let onClick = _ => setValue(value => value + 1);
66+
<button onClick> {React.int(value)} </button>;
67+
};
68+
};
69+
6170
module DummyIncrementReducerComponent = {
6271
type action =
6372
| Increment;
6473

6574
[@react.component]
6675
let make = (~initialValue=0) => {
6776
let (state, send) =
68-
React.Uncurried.useReducer(
77+
React.useReducer(
6978
(state, action) =>
7079
switch (action) {
7180
| Increment => state + 1
@@ -75,7 +84,7 @@ module DummyIncrementReducerComponent = {
7584

7685
<section>
7786
<main> {React.int(state)} </main>
78-
<button role="Increment" onClick={_ => {send(. Increment)}}>
87+
<button role="Increment" onClick={_ => {send(Increment)}}>
7988
{React.string("Increment")}
8089
</button>
8190
</section>;
@@ -90,7 +99,7 @@ module DummyReducerComponent = {
9099
[@react.component]
91100
let make = (~initialValue=0) => {
92101
let (state, send) =
93-
React.Uncurried.useReducer(
102+
React.useReducer(
94103
(state, action) =>
95104
switch (action) {
96105
| Increment => state + 1
@@ -103,10 +112,10 @@ module DummyReducerComponent = {
103112

104113
<>
105114
<main> {React.int(state)} </main>
106-
<button role="Increment" onClick={_ => send(. Increment)}>
115+
<button role="Increment" onClick={_ => send(Increment)}>
107116
{React.string("Increment")}
108117
</button>
109-
<button role="Decrement" onClick={_ => send(. Decrement)}>
118+
<button role="Decrement" onClick={_ => send(Decrement)}>
110119
{React.string("Decrement")}
111120
</button>
112121
</>;
@@ -121,7 +130,7 @@ module DummyReducerWithMapStateComponent = {
121130
[@react.component]
122131
let make = (~initialValue=0, ()) => {
123132
let (state, send) =
124-
React.Uncurried.useReducerWithMapState(
133+
React.useReducerWithMapState(
125134
(state, action) =>
126135
switch (action) {
127136
| Increment => state + 1
@@ -133,10 +142,10 @@ module DummyReducerWithMapStateComponent = {
133142

134143
<section>
135144
<main role="Counter"> state->React.int </main>
136-
<button role="Increment" onClick={_ => send(. Increment)}>
145+
<button role="Increment" onClick={_ => send(Increment)}>
137146
{React.string("Increment")}
138147
</button>
139-
<button role="Decrement" onClick={_ => send(. Decrement)}>
148+
<button role="Decrement" onClick={_ => send(Decrement)}>
140149
{React.string("Decrement")}
141150
</button>
142151
</section>;
@@ -161,13 +170,13 @@ module WithEffect = {
161170
module RerenderOnEachClick = {
162171
[@react.component]
163172
let make = (~initialValue=0, ~maxValue=3, ~callback) => {
164-
let (value, setValue) = React.Uncurried.useState(() => initialValue);
173+
let (value, setValue) = React.useState(() => initialValue);
165174
let onClick = _ =>
166175
if (value < maxValue) {
167-
setValue(. value => value + 1);
176+
setValue(value => value + 1);
168177
} else {
169178
/* Fire a setState with the same value */
170-
setValue(. value => value);
179+
setValue(value => value);
171180
};
172181

173182
<section>
@@ -243,6 +252,15 @@ describe("Hooks", () => {
243252
expect(DomTestingLibrary.getNodeText(button))->toBe("1");
244253
});
245254

255+
test("can render react components with uncurried useState", () => {
256+
let container =
257+
ReactTestingLibrary.render(<DummyStatefulAndUncurriedComponent />);
258+
let button = getByTag("button", container);
259+
expect(DomTestingLibrary.getNodeText(button))->toBe("0");
260+
FireEvent.click(button);
261+
expect(DomTestingLibrary.getNodeText(button))->toBe("1");
262+
});
263+
246264
test("can render react components with effects", () => {
247265
let container =
248266
ReactTestingLibrary.render(

0 commit comments

Comments
 (0)