Package

purescript-react-testing-library

Repository
i-am-the-slime/purescript-react-testing-library
License
MIT
Uploaded by
i-am-the-slime
Published on
2021-06-19T07:43:50Z

This are purescript wrappers for react-testing-library.

First install the node packages

npm install --save-dev @testing-library/react @testing-library/user-event jsdom jsdom-global

Example

module Test.Component.CounterSpec where

import Prelude
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import React.Basic (ReactComponent)
import React.TestingLibrary (cleanup, fireEventClick, renderComponent)
import Test.Component.Counter (mkCounter)
import Test.Spec (Spec, after_, before, describe, it)
import Test.Spec.Assertions.DOM (textContentShouldEqual)

spec  Spec Unit
spec =
  after_ cleanup
    $ before setup
    $ describe
        "A simple counter" do
        it
          "renders without errors" \counter -> do
          { findByLabelText } <- renderComponent counter {}
          elem <- findByLabelText "A simple counter"
          elem `textContentShouldEqual` "Increment: 0"
        it
          "increments when clicked" \counter -> do
          { findByLabelText } <- renderComponent counter {}
          elem <- findByLabelText "A simple counter"
          elem `textContentShouldEqual` "Increment: 0"
          fireEventClick elem
          elem `textContentShouldEqual` "Increment: 1"

setup  Aff (ReactComponent {})
setup = mkCounter # liftEffect

More examples

Check out the examples in the test folder.