@greenlabs/rescript-testing-library
v2.0.1
Published
ReScript bindings for @testing-library
Downloads
23
Readme
rescript-testing-library
Install
npm i @greenlabs/rescript-testing-library --dev
or
yarn add @greenlabs/rescript-testing-library --dev
"bs-dev-dependencies": [
"@greenlabs/rescript-testing-library"
]
Usage
module TestComponent = {
@react.component
let make = () => {
let (show, setShow) = React.useState(_ => false)
<div>
<button type_="button" onClick={_ => setShow(prev => !prev)}>
{`Toggle`->React.string}
</button>
{show ? <h1 title="my_title"> {`Hello World`->React.string} </h1> : React.null}
</div>
}
}
open! Jest
open! Expect
open! TestingLibrary.JestExpect
open! TestingLibrary.Dom
module Event = TestingLibrary.Event
testPromise("use jest dom", async () => {
let userEvent = Event.setup()
TestingLibrary.React.render(<TestComponent />)->ignore
expect(screen->ByTitle.query("my_title"))->not->toBeInTheDocument
await TestingLibrary.React.actPromise(async () => {
await (userEvent->Event.click(screen->ByText.get("Toggle")))
})
expect(screen->ByTitle.get("my_title")->Some)->toBeInTheDocument
})