JSPM

@greenlabs/rescript-testing-library

2.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q35423F
  • License MIT

ReScript bindings for @testing-library

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@greenlabs/rescript-testing-library) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    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
    })