Various testing utilities for Reacl.
Various testing utilities for Reacl.
(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.
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 a shallow renderer for testing
Create a shallow renderer for testing
(dom=? el1 el2)
Compare two React DOM elements for equality.
Compare two React DOM elements for equality.
(element-children element)
Get the children of a rendered element as a vector.
Get the children of a rendered element as a vector.
(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.
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 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 statelocal-state
is the local statemsg
is the message.This returns a pair [cmp ret]
where:
cmp
is the mock component used in the testret
is a Returned
record with app-state
, local-state
, and actions
fields.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.
(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 {...}`
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 {...}`
(render! renderer el)
Render an element into a renderer.
Render an element into a renderer.
(render-output renderer)
Get the output of rendering.
Get the output of rendering.
(render-shallowly element)
(render-shallowly element renderer)
Render an element shallowly.
Render an element shallowly.
(rendered-children element)
Retrieve children from a rendered element.
Retrieve children from a rendered element.
(simulate f & checks)
Creates an interaction, that will call f
with the
ReactTestUtils.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.
Creates an interaction, that will call `f` with the ReactTestUtils.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 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.
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 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.
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 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.
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* [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 %))))))
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 %))))))
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close