reacl2.test-util

Various testing utilities for Reacl.

->path-element

(->path-element x)

->path-element-type

(->path-element-type x)

->PathElement

(->PathElement type props-predicate)

Positional factory function for reacl2.test-util/PathElement.

after

(after message & checks)

Creates an interaction the sends the given message to the tested component, and performs the given checks afterwards. Should be used in the context a testing-class* call.

create-renderer

(create-renderer)

Create a shallow renderer for testing

descend-into-element

(descend-into-element element path)

dom=?

(dom=? el1 el2)

Compare two React DOM elements for equality.

element-children

(element-children element)

Get the children of a rendered element as a vector.

element-has-type?

(element-has-type? element tag)

Check if an element has a given type, denoted by tag.

tag may be a keyword or string with the name of a DOM element, or React or a Reacl class.

handle-message

(handle-message cl app-state args local-state msg)

Invoke the message handler of a Reacl element.

  • cl is the Reacl class.
  • app-state is the app state
  • local-state is the local state
  • msg is the message.

This returns a pair [cmp ret] where:

  • cmp is the mock component used in the test
  • ret is a Returned record with app-state, local-state, and actions fields.

hiccup-matches?

(hiccup-matches? pattern data)

instantiate&mount

(instantiate&mount clazz & args)

invoke-callback

(invoke-callback element callback event)

Invoke a callback of an element.

callback must a keyword naming the attribute (onchange).

event must be a React event - don’t forget the �#js {…}`

map->PathElement

(map->PathElement G__3568)

Factory function for reacl2.test-util/PathElement, taking a map of keywords to field values.

no-check

An empty check that does nothing.

path-element-matches?

(path-element-matches? path-element element)

PathElement

render!

(render! renderer el)

Render an element into a renderer.

render->hiccup

(render->hiccup element)

render-output

(render-output renderer)

Get the output of rendering.

render-shallowly

(render-shallowly element)(render-shallowly element renderer)

Render an element shallowly.

render-to-text

(render-to-text dom)

rendered-children

(rendered-children element)

Retrieve children from a rendered element.

simulate

(simulate f & checks)

Creates an interaction, that will call f with the React.addons.TestUtils.Simulate object and the dom node of the tested component. The simulator object has methods like click that you can call to dispatch a DOM event. The given checks are performed afterwards.

the-app-state

(the-app-state f)

Create a check on the app-state, by calling the given function f with the app-state at that time. Should be used in the context a testing-class* call.

the-dom

(the-dom f)

Create a check on the dom rendered by a component, by calling the given function f with the dom-node at that time. Should be used in the context a testing-class* call.

the-local-state

(the-local-state f)

Create a check on the local-state, by calling the given function f with the local-state at that time. Should be used in the context a testing-class* call.

with-testing-class*

(with-testing-class* [clazz & args] initial-check & interactions)

Instantiates the given class with an initial app-state and arguments, performs the initial-check and all given interactions.

A ‘check’ is a function taking a function to retrieve the current app-state and a function retrieving the current dom node as rendered by the class - see the-app-state and the-dom to create usual checks.

An ‘interaction’ is a function taking a function to send a message to the component, and returning a sequence of checks - see after to create a usual interaction.

Note that check implementations should usually contain clojure-test assertions. A common pattern could be:

(with-testing-class* [my-class nil “en”] (the-dom #(is (= “Hello World” (.-innerText %)))) (after (set-lang-message “de”) (the-dom #(is (= “Hallo Welt” (.-innerText %))))))