This library wraps the Chai assertion library, so it can be used from ClojureScript in a convenient way.
Familiarity with the Chai library itself is assume. Refer to the Chai guide for an introduction.
[chai-latte "0.2.0"]
Read the Changelog for a list of changes in the current version.
When running on NodeJS, simply install Chai via npm.
npm install chai
When testing front end code in a browser or in a headless setup, you need to provide a browser build of chai.js and any plugins to Chai that you may be using, which are usually included via a script tag.
This library will try to autodetect if the environment is a browser or nodejs.
To write an assertion construct a form of the following shape:
(ns mylib.test.core
(require [latte.chai :refer (expect)]))
...
(expect <actual> <test-expression> <expectation>)
valid forms would be:
(expect 1 :to.equal 1)
(expect 1 :not.to.equal 2)
Test expressions are always keywords of dot delimited fragments. All of the Chai chainable language constructs are available. See Chai's expect API as a reference.
All values after the test expression are passed as parameters to the test method given by the test expression. If the test epxression points to a property instead of a method, no parameters are allowed.
(epxect true :to.be.ok)
Currently only the expect API of Chai is wrapped.
Whenever required the wrapper extends the Chai chainable language pieces to deal with Clojure values. As an example the following is a passing assertion:
(expect {:a 1 :b 2} :to.equal {:a 1 :b 2})
because Chai is extended to respect Clojure's concept of equality when dealing with complex data structures.
Due to an implementation detail in Chai it is currently not possible to properly support the following assertion.
(expect [1 2 3] :to.incude 1)
While using this library, an additional method is present in Chai, which can be used in the following way.
(expect [1 2 3] :to.include.value 1)