Q provides gadgets for spies, and aims to make testing involving complex dependencies easier. It provides helper functions for creating fakes, stubs and spies - as well as ways to inspect what was called on them after-the-fact.
[q "0.1.0"]
(ns test.foo
(:require [q.gadgets :as q]))
(defn foo [x] ...)
(defn bar [y] ...)
(deftest foo-is-called
(q/with-spy [foo bar]
(bar)
(is (q/called-once bar))))
Q is based on Bond, but with a wider variety of higher-level functions available. Much of the functionality is modelled on SinonJS
Takes a function fn
, and returns a spied-fn
that has the same behaviour
except it records information about its invocations.
Takes a vector of function vars fns
and executes body
with those functions
replaced with spies.
Returns a vector of call maps, representing each call of fn
.
Each map will contain :args
a vector of the arguments it was called with, and
either :return
for the return value or :throw
for the exception thrown.
Returns the call map for the n
th time spied-fn
was called.
Returns the most recent call map for spied-fn
.
Returns true if spied-fn
was called.
Returns true if spied-fn
was called once.
Returns the number of times spied-fn
was called.
Returns true if spied-fn
was called with args
.
When fns
is a vector, accepts a list of function vars and executes body
with
those functions replaced with spies that return nil.
When fns
is a map, accepts a mapping of function vars to return values, and
executes body
with those functions replaced with spies that return the desired
return value.
Accepts a map of function vars to functions, and executes body
with the
original functions spied and replaced with the supplied implementations.
Distributed under the Eclipse Public License.