(async & forms)
Similar to JS's async/await. Wraps the body of async
in a promise and allows for the use
of await
, which when called will wait for the promise to finish before continuing execution
of the promise body.
Allows await
in a few cases:
Top level:
(async
(await my-promise)
(some-fn))
Inside of let
:
(async
(let [a-keyword :kw]
(await (an-async-fn a-keyword))
(some-fn)))
Inside of the binding value of let
:
(async
(let [a-keyword :kw
my-async-binding (await my-promise)]
(some-fn)))
Similar to JS's async/await. Wraps the body of `async` in a promise and allows for the use of `await`, which when called will wait for the promise to finish before continuing execution of the promise body. Allows `await` in a few cases: *Top level*: ``` (async (await my-promise) (some-fn)) ``` *Inside of `let`*: ``` (async (let [a-keyword :kw] (await (an-async-fn a-keyword)) (some-fn))) ``` *Inside of the binding value of `let`*: ``` (async (let [a-keyword :kw my-async-binding (await my-promise)] (some-fn))) ```
(setup-mocks bindings)
Similar to with-redefs
, but allows for mocking at the top level or within a describe block without needing to wrap
individual tests in with-redefs
/with-redefs+
. Set up and automatically cleans up mocks before and after each test.
Note: this function does not work inside of an it
block. If you need to mock something for an individual test case,
use with-mocks
.
Example:
(describe "My test"
(h/setup-mocks [api-client/http-post+ (spy #(js/Promise.resolve))])
(it "should make a request when called"
(some-requesting-fn)
(m/called-with? api-client/http-post+ body)))
Similar to `with-redefs`, but allows for mocking at the top level or within a describe block without needing to wrap individual tests in `with-redefs`/`with-redefs+`. Set up and automatically cleans up mocks before and after each test. Note: this function does not work inside of an `it` block. If you need to mock something for an individual test case, use `with-mocks`. Example: ```clj (describe "My test" (h/setup-mocks [api-client/http-post+ (spy #(js/Promise.resolve))]) (it "should make a request when called" (some-requesting-fn) (m/called-with? api-client/http-post+ body))) ```
(with-mocks bindings & body)
Similar to with-redefs
but handles bodies that may have promises.
Similar to `with-redefs` but handles bodies that may have promises.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close