clj-di.test

Helpres for tests.

with-fresh-dependencies

macro

(with-fresh-dependencies & body)

Test helper for running tests without registered dependencies.

Usage:

(with-fresh-dependencies ...)

This helper very useful with use-fixtures, for running all tests without registered dependencies use:

(use-fixtures :each
  (fn [f] (with-fresh-dependencies (f))))

with-registered

macro

(with-registered key-dep-pairs & body)

Register dependencies, run code block and forget about dependencies.

Usage:

(with-registered [:http http-client
                  :logger logger]
  ...)

with-reset

macro

(with-reset bindings & body)

CLJS only

binding => var-symbol temp-value-expr

Temporarily redefines vars while executing the body. The temp-value-exprs will be evaluated and each resulting value will replace in parallel the root value of its var. After the body is executed, the root values of all the vars will be set back to their old values. Useful for mocking out functions during testing.

Usage:

(with-reset [http/get (fn [url] :test)]
  (is (= (http/get :url) :test)))