API for cljs.test - clojurescript


Full namespace name: cljs.test

Overview





Public Variables and Functions



are

macro
Usage: (are argv expr & args)
Checks multiple assertions with a template expression.
See clojure.template/do-template for an explanation of
templates.

Example: (are [x y] (= x y)  
              2 (+ 1 1)
              4 (* 2 2))
Expands to: 
         (do (is (= 2 (+ 1 1)))
             (is (= 4 (* 2 2))))

Note: This breaks some reporting features, such as line numbers.

    
    
    
  


assert-any

function
Usage: (assert-any msg form)
Returns generic assertion code for any test, including macros, Java
method calls, or isolated symbols.

    
    
    
  


assert-predicate

function
Usage: (assert-predicate msg form)
Returns generic assertion code for any functional predicate.  The
'expected' argument to 'report' will contains the original form, the
'actual' argument will contain the form with all its sub-forms
evaluated.  If the predicate returns false, the 'actual' form will
be wrapped in (not...).

    
    
    
  


async

macro
Usage: (async done & body)
Wraps body as a CPS function that can be returned from a test to
continue asynchronously.  Binds done to a function that must be
invoked once and from an async context after any assertions.

(deftest example-with-timeout
  (async done
    (js/setTimeout (fn []
                     ;; make assertions in async context...
                     (done) ;; ...then call done
                     )
                   0)))

    
    
    
  


deftest

macro
Usage: (deftest name & body)
Defines a test function with no arguments.  Test functions may call
other tests, so tests may be composed.  If you compose tests, you
should also define a function named test-ns-hook; run-tests will
call test-ns-hook instead of testing all vars.

Note: Actually, the test body goes in the :test metadata on the var,
and the real function (the value of the var) calls test-var on
itself.

When cljs.analyzer/*load-tests* is false, deftest is ignored.

    
    
    
  


function?

function
Usage: (function? menv x)
Returns true if argument is a function or a symbol that resolves to
a function (not a macro).

    
    
    
  


is

macro
Usage: (is form)
       (is form msg)
Generic assertion macro.  'form' is any predicate test.
'msg' is an optional message to attach to the assertion.

Example: (is (= 4 (+ 2 2)) "Two plus two should be 4")

Special forms:

(is (thrown? c body)) checks that an instance of c is thrown from
body, fails if not; then returns the thing thrown.

(is (thrown-with-msg? c re body)) checks that an instance of c is
thrown AND that the message on the exception matches (with
re-find) the regular expression re.

    
    
    
  


run-all-tests

macro
Usage: (run-all-tests)
       (run-all-tests re)
       (run-all-tests re env)
Runs all tests in all namespaces; prints results.
Optional argument is a regular expression; only namespaces with
names matching the regular expression (with re-matches) will be
tested.

    
    
    
  


run-tests

macro
Usage: (run-tests)
       (run-tests env-or-ns)
       (run-tests env-or-ns & namespaces)
Runs all tests in the given namespaces; prints results.
Defaults to current namespace if none given. Does not return a meaningful
value due to the possiblity of asynchronous execution. To detect test
completion add a :end-run-tests method case to the cljs.test/report
multimethod.

    
    
    
  


run-tests-block

macro
Usage: (run-tests-block env-or-ns & namespaces)
Like test-vars, but returns a block for further composition and
later execution.

    
    
    
  


test-all-vars

macro
Usage: (test-all-vars [quote ns :as form])
Calls test-vars on every var with :test metadata interned in the
namespace, with fixtures.

    
    
    
  


test-ns

macro
Usage: (test-ns ns)
       (test-ns env [quote ns :as form])
If the namespace defines a function named test-ns-hook, calls that.
Otherwise, calls test-all-vars on the namespace.  'ns' is a
namespace object or a symbol.

Internally binds *report-counters* to a ref initialized to
*initial-report-counters*.  

    
    
    
  


test-ns-block

macro
Usage: (test-ns-block env [quote ns :as form])
Like test-ns, but returns a block for further composition and
later execution.  Does not clear the current env.

    
    
    
  


testing

macro
Usage: (testing string & body)
Adds a new string to the list of testing contexts.  May be nested,
but must occur inside a test function (deftest).

    
    
    
  


try-expr

macro
Usage: (try-expr msg form)
Used by the 'is' macro to catch unexpected exceptions.
You don't call this.

    
    
    
  
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.