Skip to content
This repository has been archived by the owner on Jul 8, 2021. It is now read-only.

Commit

Permalink
chore(platform): rewrite to JSX 3
Browse files Browse the repository at this point in the history
BREAKING CHANGE: it won't work with JSX 2 anymore
  • Loading branch information
erykpiast committed Jul 28, 2020
1 parent a8be775 commit edded40
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 112 deletions.
2 changes: 1 addition & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bs-enzyme",
"reason": { "react-jsx": 2 },
"reason": { "react-jsx": 3 },
"bs-dependencies": ["reason-react"],
"bs-dev-dependencies": ["@glennsl/bs-jest"],
"bsc-flags": ["-bs-super-errors"],
Expand Down
14 changes: 10 additions & 4 deletions src/Enzyme.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 28 additions & 44 deletions src/__tests__/DummyComponent.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions src/__tests__/DummyComponent.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ type state = {clicked: bool};
type action =
| Click;

let se = ReasonReact.string;
let se = React.string;

let component = ReasonReact.reducerComponent("DummyComponent");

let make = (~title, _children) => {
...component,
initialState: () => {clicked: false},
reducer: (action, state) =>
[@react.component]
let make = (~title) => {
let (state, dispatch) = React.useReducer(
(state, action) =>
switch action {
| Click => ReasonReact.Update({clicked: ! state.clicked})
| Click => {clicked: !state.clicked}
},
render: (self) =>
<div className="dummy">
<div id="header"> <h1> (se(title)) </h1> </div>
<div id="content">
<button id="click-me" onClick=((_event) => self.send(Click))>
(se(self.state.clicked ? "I've been clicked!" : "Click Me!"))
</button>
<ul id="list"> <li> (se("One")) </li> <li> (se("Two")) </li> <li> (se("Three")) </li> </ul>
</div>
{clicked: false}
);

<div className="dummy">
<div id="header"> <h1> (se(title)) </h1> </div>
<div id="content">
<button id="click-me" onClick=((_event) => dispatch(Click))>
(se(state.clicked ? "I've been clicked!" : "Click Me!"))
</button>
<ul id="list"> <li> (se("One")) </li> <li> (se("Two")) </li> <li> (se("Three")) </li> </ul>
</div>
</div>
};
89 changes: 47 additions & 42 deletions src/__tests__/DummyComponent_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/__tests__/DummyComponent_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ describe(
"initially has its `clicked` state set to false",
() => {
let wrapper = setup();
let {clicked}: DummyComponent.state = Enzyme.Shallow.state(wrapper);
expect(clicked) |> toBe(false)
let button = wrapper |> Enzyme.Shallow.find("#click-me");
let buttonText = button |> Enzyme.Shallow.text;
expect(buttonText) |> toEqual("Click Me!");

}
);
test(
Expand Down Expand Up @@ -141,8 +143,9 @@ describe(
"initially has its `clicked` state set to false",
() => {
let wrapper = setup();
let {clicked}: DummyComponent.state = Enzyme.Mount.state(wrapper);
expect(clicked) |> toBe(false)
let button = wrapper |> Enzyme.Mount.find("#click-me");
let buttonText = button |> Enzyme.Mount.text
expect(buttonText) |> toEqual("Click Me!")
}
);
test(
Expand Down

0 comments on commit edded40

Please sign in to comment.