Back to Testing Library

bs-jest-dom

docs/ecosystem-bs-jest-dom.mdx

latest1.2 KB
Original Source

bs-jest-dom is a companion library for bs-react-testing-library that provides custom DOM element matchers for Jest in ReasonML via BuckleScript.

bash
npm install --save-dev bs-jest-dom

Check out jest-dom's documentation for a full list of available matchers.

Setup

json
{
  "bs-dev-dependencies": ["bs-jest-dom"]
}

Example

reason
open Jest;
open JestDom;
open ReactTestingLibrary;

module Heading = {
  let component = ReasonReact.statelessComponent("Heading");

  let make = (~text, _children) => {
    ...component,
    render: _self =>
      <h1> {ReasonReact.string(text)} </h1>,
  };
};

test("renders with text", () =>
  <Heading text="Hello, World!" />
  |> render
  |> getByText(~matcher=`Str("Hello, World!"))
  |> expect
  |> toBeInTheDocument
);

More Examples

You can find more bs-jest-dom examples at wyze/bs-jest-dom/src/__tests__.