(async-test & params)
Starts an "async test". Basically, wraps everything around promesa.core/do!
to
await for promises if they appear, and awaits for 2s to see if the test will pass -
otherwise, the test fails with a timeout exception. It also will capture errors from
the promises, re-throw instead of not ending the test.
This macro is specially useful on ClojureScript tests, where async tests are
really hard to get it right. If you intend to use async tests, also use the testing
macro in this same namespace - it'll also await for promises and play nice with this
code.
async-test
expects a tst description, and the second argument can be a map
containing :timeout
and :teardown
. :timeout
is a time, in miliseconds, that
the test will await until it fails, and teardown is a code (NOT a function)
that will run when the test ends - both when it completes, fails, or timeouts. If
the second parameter is not a map, it'l be interpreted as the test body.
Examples:
(ns some-test
(:require [check.async :as async]
[clojure.test :as t]))
; A simple async test
(t/deftest sum
(async/async-test "some async function"
(async/testing "will sum 2 numbers"
; if sum returns a promise, it'll await for it to resolve
(async/check (sum 1 2) => 3))))
; A complete example
(def conn (atom nil))
(t/deftest db-query
(async/async-test "searches for people"
{:timeout 4000, :teardown (db/close! @conn)}
; It'll await for this promise to resolve before continuing
(.then (db/connect!) #(reset! conn %))
; It'll also await for this code
(async/check (db/query! @conn {:person-id 1})
=> [{:person-id 1, :name "Person Name"}])))
See also: check.async/check
, check.async/testing
Starts an "async test". Basically, wraps everything around `promesa.core/do!` to await for promises if they appear, and awaits for 2s to see if the test will pass - otherwise, the test fails with a timeout exception. It also will capture errors from the promises, re-throw instead of not ending the test. This macro is **specially useful** on ClojureScript tests, where async tests are really hard to get it right. If you intend to use async tests, also use the `testing` macro in this same namespace - it'll also await for promises and play nice with this code. `async-test` expects a tst description, and the second argument can be a map containing `:timeout` and `:teardown`. `:timeout` is a time, in miliseconds, that the test will await until it fails, and teardown is a **code** (NOT a function) that will run when the test ends - both when it completes, fails, or timeouts. If the second parameter is not a map, it'l be interpreted as the test body. Examples: ``` (ns some-test (:require [check.async :as async] [clojure.test :as t])) ; A simple async test (t/deftest sum (async/async-test "some async function" (async/testing "will sum 2 numbers" ; if sum returns a promise, it'll await for it to resolve (async/check (sum 1 2) => 3)))) ; A complete example (def conn (atom nil)) (t/deftest db-query (async/async-test "searches for people" {:timeout 4000, :teardown (db/close! @conn)} ; It'll await for this promise to resolve before continuing (.then (db/connect!) #(reset! conn %)) ; It'll also await for this code (async/check (db/query! @conn {:person-id 1}) => [{:person-id 1, :name "Person Name"}]))) ``` See also: `check.async/check`, `check.async/testing`
(async-test* description timeout teardown-delay go-thread)
(async-test* description timeout teardown prom)
(await! chan)
(check sub-expression)
(check left arrow right)
Checks for an expression, using a matcher (or arrow), in an async context.
check
have two APIs: one that can be used as is
, but only works for matchers or
arrows, and other that is similar to midje's fact
. To us the first version, you can
use:
; This will use the `nubank/matcher-combinators` match? to check equality
(check (=> <expected> <actual>))
; This will use the `expectations` library to check equality
(check (=expect=> <expected> <actual>))
; Or you can use the midje-like assertions
(check <actual> => <expected>)
This version of check
will "await" for promises and also return promises. It also
is not vulnerable to problems with matcher-combinators and clojure.test with async
code either.
See also: check.core/check
, check.async/async-test
Checks for an expression, using a matcher (or arrow), in an async context. `check` have two APIs: one that can be used as `is`, but only works for matchers or arrows, and other that is similar to midje's `fact`. To us the first version, you can use: ```clojure ; This will use the `nubank/matcher-combinators` match? to check equality (check (=> <expected> <actual>)) ; This will use the `expectations` library to check equality (check (=expect=> <expected> <actual>)) ; Or you can use the midje-like assertions (check <actual> => <expected>) ``` This version of `check` will "await" for promises and also return promises. It also is not vulnerable to problems with matcher-combinators and clojure.test with async code either. See also: `check.core/check`, `check.async/async-test`
(let-testing description bindings & body)
Equivalent to:
(testing <description>
(p/let <bindings>
(p/do!
<body>)))
Or, more specifically, allows to have a testing
block that honors async bindings
(it'll await all promises) and async bodies (it'll await all commands that return
promises)
Equivalent to: ``` (testing <description> (p/let <bindings> (p/do! <body>))) ``` Or, more specifically, allows to have a `testing` block that honors async bindings (it'll await all promises) and async bodies (it'll await all commands that return promises)
(testing description & body)
Same as clojure.test/testing, but honors async tests - that is, if a failure occurs
inside this testing
block, the description will be shown on the console
Same as clojure.test/testing, but honors async tests - that is, if a failure occurs inside this `testing` block, the description will be shown on the console
(to-promise promise-or-chan)
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close