rescript-react-testing-library

1.3.0 • Public • Published

ReScript React Testing Library

npm GitHub Workflow Status Codecov

ReScript bindings for testing-library/react.

Install

npm install --save-dev rescript-react-testing-library
# or yarn
yarn add --dev rescript-react-testing-library

Update your bsconfig file:

{
  "bs-dev-dependencies": ["rescript-react-testing-library"]
}

Usage

open Jest
open Expect
open ReactTestingLibrary

// Make it pipe-first:
let toMatchSnapshot = a => a |> Expect.toMatchSnapshot

module DummyComponent = {
  @react.component
  let make = () => {
    <div>
      <label> {React.string("Choose a color")} </label>
      <select>
        <option> {React.string("Red")} </option>
        <option> {React.string("Green")} </option>
        <option onClick={_ => Js.log("Blue")}> {React.string("Blue")} </option>
      </select>
    </div>
  }
}

describe("DummyComponent", () => {
  beforeEach(() => {
    <DummyComponent />->renderOnScreen
  })

  test("render Red option", () => {
    screen
    ->getByRole(~matcher=#Str("option"), ~options=makeByRoleOptions(~name="Red", ()))
    ->expect
    ->toMatchSnapshot
  })

  test("render Green option", () => {
    screen
    ->getByRole(~matcher=#Str("option"), ~options=makeByRoleOptions(~name="Green", ()))
    ->expect
    ->toMatchSnapshot
  })

  test("render Blue option", () => {
    screen
    ->getByRole(~matcher=#Str("option"), ~options=makeByRoleOptions(~name="Blue", ()))
    ->expect
    ->toMatchSnapshot
  })
})

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.3.0
    27
    • latest

Version History

Package Sidebar

Install

npm i rescript-react-testing-library

Weekly Downloads

27

Version

1.3.0

License

MIT

Unpacked Size

16.1 kB

Total Files

11

Last publish

Collaborators

  • brnrdog