1.15.0 • Published 3 years ago

rescript-dom-testing-library v1.15.0

Weekly downloads
591
License
MIT
Repository
-
Last release
3 years ago

ReScript DOM Testing Library

npm GitHub Workflow Status Codecov

ReScript bindings for testing-library/dom.

Install

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

Update your bsconfig file:

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

Usage

open Jest
open JestDom
open DomTestingLibrary

let render = %raw(`
  function(html) {
    const body = document.querySelector('body')
    body.innerHTML = html
    return body
  }
`)

let example = render(`
<label htmlFor="color">
  Select a color
  <select id="color">
    <option>Red</option>
    <option>Green</option>
    <option>Blue</option>
  </select>
</label>
`)

test("renders label", () => {
  example
  ->getByLabelText(~matcher=#RegExp(Js.Re.fromString("select a color")))
  ->expect
  ->toBeInTheDocument
})

test("renders red option (using string)", () => {
  let options = makeByRoleOptions(~name="Red", ())

  example
  ->getByRole(~matcher=#Str("option"), ~options)
  ->expect
  ->toBeInTheDocument
})

test("renders red option (using regular expression)", () => {
  let options = makeByRoleOptionsWithRegex(
    ~name=Js.Re.fromStringWithFlags("/green/", ~flags="i"),
    (),
  )

  example
  ->getByRole(~matcher=#Str("option"), ~options)
  ->expect
  ->toBeInTheDocument
})

test("renders blue option (using custom function)", () => {
  let options = makeByRoleOptionsWithFunction(~name=(content, _element) => content === "Blue", ())

  example
  ->getByRole(~matcher=#Str("option"), ~options)
  ->expect
  ->toBeInTheDocument
})

See the tests for more examples.

1.15.0

3 years ago

1.14.1

3 years ago

1.14.0

3 years ago

1.13.0

3 years ago

1.12.0

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.11.0

3 years ago

1.10.0

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

2.1.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago