-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Install melange-testing-library * Install melange-testing-library npm deps * Vendor melange-testing-library * Fix Form__test with RTL * Start migrating Hooks__test * Remove dependency * Remove unused code from Form__test * Add a jest-devtoolsgs * Add a jest-devtools * Migrate Hooks and Form into RTL * Add demo to manually test easily * Use Uncurried for tests * Migrate all React__test * Force install since we are dealing with R19 * Snapshot with lower {} * Enable ref in ppx * Add jest test for ref * Remove jest from demo/dune * Add comment on install --force * Improve test from checking ref * Bind React.act and React.actAsync * Bind React.act and React.actAsync
- Loading branch information
Showing
4 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
open Jest; | ||
open Expect; | ||
|
||
module Button_with_ref = { | ||
[@react.component] | ||
let make = (~children, ~ref) => { | ||
<button ref role="FancyButton"> children </button>; | ||
}; | ||
}; | ||
|
||
let getByRole = (role, container) => { | ||
ReactTestingLibrary.getByRole(~matcher=`Str(role), container); | ||
}; | ||
|
||
[@mel.get] external innerHTML: Dom.element => string = "innerHTML"; | ||
|
||
describe("ref", () => { | ||
test("can be passed as prop to a component", () => { | ||
let domRef = React.createRef(); | ||
let container = | ||
ReactTestingLibrary.render( | ||
<Button_with_ref ref={ReactDOM.Ref.domRef(domRef)}> | ||
{React.string("Click me")} | ||
</Button_with_ref>, | ||
); | ||
let button = getByRole("FancyButton", container); | ||
expect(button->innerHTML)->toBe("Click me"); | ||
let content = | ||
switch (Js.Nullable.toOption(domRef.current)) { | ||
| Some(element) => element->innerHTML | ||
| None => failwith("No element found") | ||
}; | ||
expect(content)->toBe("Click me"); | ||
}) | ||
}); |