|
| 1 | +# ReScript React Testing Library |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/rescript-react-testing-library) |
| 4 | +[](https://github.com/brnrdog/rescript-react-testing-library/actions/workflows/release.yml) |
| 5 | + |
| 6 | + |
| 7 | +ReScript bindings for [testing-library/react](https://github.com/testing-library/react-testing-library/). |
| 8 | + |
| 9 | +## Install |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install --save-dev rescript-react-testing-library |
| 13 | +# or yarn |
| 14 | +yarn add --dev rescript-react-testing-library |
| 15 | +``` |
| 16 | + |
| 17 | +Update your bsconfig file: |
| 18 | + |
| 19 | +```json |
| 20 | +{ |
| 21 | + "bs-dev-dependencies": ["rescript-react-testing-library"] |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +```res |
| 28 | +open Jest |
| 29 | +open Expect |
| 30 | +open ReactTestingLibrary |
| 31 | +
|
| 32 | +module Dummy = { |
| 33 | + @react.component |
| 34 | + let make = () => { |
| 35 | + <div> |
| 36 | + <label> {React.string("Choose a color")} </label> |
| 37 | + <select> |
| 38 | + <option> {React.string("Red")} </option> |
| 39 | + <option> {React.string("Green")} </option> |
| 40 | + <option> {React.string("Blue")} </option> |
| 41 | + </select> |
| 42 | + </div> |
| 43 | + } |
| 44 | +} |
| 45 | +
|
| 46 | +let setup = () => { |
| 47 | + renderElement(<Dummy />) |
| 48 | +} |
| 49 | +
|
| 50 | +test("render red option", () => { |
| 51 | + setup()->getByRole(~matcher=#Str("option"), ~options=makeByRoleOptions(~name="Red", ())) |
| 52 | + |> expect |
| 53 | + |> toMatchSnapshot |
| 54 | +}) |
| 55 | +
|
| 56 | +test("render red option", () => { |
| 57 | + setup()->getByRole(~matcher=#Str("option"), ~options=makeByRoleOptions(~name="Green", ())) |
| 58 | + |> expect |
| 59 | + |> toMatchSnapshot |
| 60 | +}) |
| 61 | +
|
| 62 | +test("render red option", () => { |
| 63 | + setup()->getByRole(~matcher=#Str("option"), ~options=makeByRoleOptions(~name="Blue", ())) |
| 64 | + |> expect |
| 65 | + |> toMatchSnapshot |
| 66 | +}) |
| 67 | +``` |
0 commit comments