Skip to main content

with-redefs

macrov1.7

cljs.core/with-redefs

Available in:BBCLJCLJS
(with-redefs [bindings & body])
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. Note that under advanced compilation vars are statically resolved, preventing with-redef usage. If var redefinition is desired in a production setting then the var to be redefined must be declared ^:dynamic.

No examples yet. Be the first to add one!