Liking cljdoc? Tell your friends :D

reacl-c.test-util.dom-testing

cljs

This namespace builds upon the React Testing Library to enable unit tests of the functinality of Reacl-c items.

The basic functionality is that you render your item to the DOM in a certain state, check that certain elements are there, maybe simulate user interactions with it and check again:

(dt/rendering
  (dom/button {:onClick (fn [st _] (* 2 st))} "Button")
  :state 42
  (fn [env]
    (is (some? (dt/query env (dt/by-text "Button"))))
    (dt/fire-event (dt/get env (dt/by-text "Button")) :click)
    (is (= 84 (dt/current-state env)))))

You can also interact with the item via messages (send-message!), and check for the actions it emits (queue-actions and pop-action!).

If your item has an asynchronous behaviour, e.g. starts a timeout before it changes its contents you can make your test asynchronous as well by using promises. Functions that are labelled asynchronous here, for example find, do return a promise. The library cljs-async can be handy to write asynchronous tests.

This namespace builds upon the [React Testing
Library](https://testing-library.com/docs/react-testing-library/intro/)
to enable unit tests of the functinality of Reacl-c items.

The basic functionality is that you render your item to the DOM in a
certain state, check that certain elements are there, maybe simulate
user interactions with it and check again:

```
(dt/rendering
  (dom/button {:onClick (fn [st _] (* 2 st))} "Button")
  :state 42
  (fn [env]
    (is (some? (dt/query env (dt/by-text "Button"))))
    (dt/fire-event (dt/get env (dt/by-text "Button")) :click)
    (is (= 84 (dt/current-state env)))))
```

You can also interact with the item via
messages ([[send-message!]]), and check for the actions it
emits ([[queue-actions]] and [[pop-action!]]).

If your item has an asynchronous behaviour, e.g. starts a timeout
before it changes its contents you can make your test asynchronous
as well by using promises. Functions that are labelled asynchronous
here, for example [[find]], do return a promise. The
library [cljs-async](https://github.com/active-group/cljs-async) can
be handy to write asynchronous tests.
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close