(invoke func)Marks a function to be dynamically invoked on mock calls. Matching calls will invoke the function with the received arguments and return the output.
Example:
(providing
[(one-fn :invoke-fn) (invoke identity)]
(is (= :invoke-fn (one-fn :invoke-fn))))
Marks a function to be dynamically invoked on mock calls. Matching calls will invoke the function with the received arguments and return the output. Example: ``` (providing [(one-fn :invoke-fn) (invoke identity)] (is (= :invoke-fn (one-fn :invoke-fn)))) ```
(providing bindings & body)Replaces functions with mocks. These mocks return preconfigured values when called with the expected arguments.
(providing
[(fn-name &args) return-value
...]
test-body)
Example:
(providing
[(one-fn) :result]
(is (= :result (one-fn))))
Replaces functions with mocks. These mocks return preconfigured values when called with the expected arguments. ``` (providing [(fn-name &args) return-value ...] test-body) ``` Example: ``` (providing [(one-fn) :result] (is (= :result (one-fn)))) ```
(raise exception)Creates a mock behavior that throws the given exception when the mock is called.
This can be used to simulate error scenarios in tests by configuring a mock to throw a specific exception.
Example:
(providing
[(one-fn) (raise (ex-info "error!" {}))]
(is (thrown-with-msg? ExceptionInfo #"error!" (one-fn))))
Creates a mock behavior that throws the given exception when the mock is called.
This can be used to simulate error scenarios in tests by configuring a mock
to throw a specific exception.
Example:
```
(providing
[(one-fn) (raise (ex-info "error!" {}))]
(is (thrown-with-msg? ExceptionInfo #"error!" (one-fn))))
```(verifying bindings & body)Replaces functions with mocks. Verifies that all calls where performed the expected number of times.
(verifying
[(fn-name &args) return-value call-count-matcher
...]
test-body)
Example:
(verifying
[(one-fn :argument) :result (exactly 1)]
(is (= :result (one-fn :argument))))
Replaces functions with mocks. Verifies that all calls where performed the expected number of times. ``` (verifying [(fn-name &args) return-value call-count-matcher ...] test-body) ``` Example: ``` (verifying [(one-fn :argument) :result (exactly 1)] (is (= :result (one-fn :argument)))) ```
(verifying-eventually patience-cfg bindings & body)Replaces functions with mocks. Verifies that all calls where performed the expected number of times. Performs this verification repeatedly, pausing for the specified interval between checks, until all expectations are met or the maximum number of attempts is exceeded.
(verifying-eventually
{:max-attempts max-attempts-num :interval-ms interval-between-attempts-ms}
[(fn-name &args) return-value call-count-matcher
...]
test-body)
Example:
(verifying-eventually
{:max-attempts 50 :interval-ms 20}
[(f/one-fn) :mocked (matchers/exactly 1)]
(future (Thread/sleep 50) (f/one-fn))))
Replaces functions with mocks. Verifies that all calls where performed the
expected number of times. Performs this verification repeatedly, pausing for
the specified interval between checks, until all expectations are met or the
maximum number of attempts is exceeded.
```
(verifying-eventually
{:max-attempts max-attempts-num :interval-ms interval-between-attempts-ms}
[(fn-name &args) return-value call-count-matcher
...]
test-body)
```
Example:
```
(verifying-eventually
{:max-attempts 50 :interval-ms 20}
[(f/one-fn) :mocked (matchers/exactly 1)]
(future (Thread/sleep 50) (f/one-fn))))
```cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |