Skip to content

Commit

Permalink
Change type of cleanup fun, fix local test run
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Strelkov committed Jun 8, 2020
1 parent 12e7874 commit cb4c4b0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ReactTestingLibrary.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type renderOptions = {
};

[@bs.module "@testing-library/react"]
external cleanup: unit => unit = "cleanup";
external cleanup: unit => Js.Promise.t(unit) = "cleanup";

[@bs.module "@testing-library/react"]
external _act: (unit => Js.undefined(Js.Promise.t('a))) => unit = "act";
Expand Down
2 changes: 1 addition & 1 deletion src/ReactTestingLibrary.rei
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type renderOptions = {
};

[@bs.module "@testing-library/react"]
external cleanup: unit => unit = "cleanup";
external cleanup: unit => Js.Promise.t(unit) = "cleanup";

let act: (unit => unit) => unit;

Expand Down
35 changes: 26 additions & 9 deletions src/__tests__/ReactTestingLibrary_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ module Counter = {

[@react.component]
let make = () => {
let (state, dispatch) = React.useReducer(
(state, action) =>
switch (action) {
| Inc => state + 1
| Dec => state - 1
},
0
);
let (state, dispatch) =
React.useReducer(
(state, action) =>
switch (action) {
| Inc => state + 1
| Dec => state - 1
},
0,
);

<div>
{ReasonReact.string("Count: " ++ string_of_int(state))}
Expand All @@ -33,7 +34,7 @@ module Counter = {
<button onClick={_event => dispatch(Dec)}>
{ReasonReact.string("-")}
</button>
</div>
</div>;
};
};

Expand Down Expand Up @@ -685,4 +686,20 @@ describe("ReactTestingLibrary", () => {
|> expect
|> toMatchSnapshot;
});

testPromise("Cleaunp, (element not found)", () => {
let result = element |> render;

cleanup()
|> Js.Promise.(
then_(_ => {
Js.Promise.resolve(
result
|> queryByTestId(~matcher=`Str("h1-heading"))
|> expect
|> toMatchSnapshot,
)
})
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ exports[`ReactTestingLibrary ByTitle queryByTitle works 1`] = `
/>
`;

exports[`ReactTestingLibrary Cleaunp, (element not found) 1`] = `null`;

exports[`ReactTestingLibrary act works 1`] = `
<div>
Count: 1
Expand Down

0 comments on commit cb4c4b0

Please sign in to comment.