Package

purescript-react-enzyme

Repository
alvart/purescript-react-enzyme
License
MIT
Uploaded by
alvart
Published on
2021-01-20T16:53:08Z

Build Status Pursuit

Purescript bindings for the Enzyme library.

Quickstart

Setting up the test environment before running any test

Before you write any unit tests with Enzyme, make sure to configure the Enzyme Adapter and the Global DOM if you are planning to use Full wrappers as opposed to Shallow ones.

Main.purs

import Effect (Effect)
import Effect.Aff (launchAff_)
import Enzyme (configure, withGlobalDOM)
import Prelude
import Test.Spec.Reporter.Console (consoleReporter)
import Test.Spec.Runner (runSpec)

main :: Effect Unit
main =
  do
  configure
  withGlobalDOM
  launchAff_ $ runSpec [ consoleReporter ]
    do
    calculatorSpec
    todoSpec
    enzymeSpec

Writing unit tests

Enzyme.purs

import Effect.Class (liftEffect)
import Enzyme (children, length, mount)
import Prelude
import React.DOM (button', div', span') as React
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual)

spec :: Spec Unit
spec =
  do
  describe "Traversing"
    do
    it "counts the number of children nodes"
      do
      node <-
        liftEffect $ mount $ React.div' [ React.span' [ ], React.button' [ ] ]
      count <- liftEffect $ children node >>= length
      count `shouldEqual` 2

More examples

There are examples for every function in this library inside the test folder of this repository.