Liking cljdoc? Tell your friends :D

me.pmatiello.mockfn.plain


invokeclj

(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))))
```
sourceraw docstring

providingcljmacro

(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))))
```
sourceraw docstring

raiseclj

(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))))
```
sourceraw docstring

verifyingcljmacro

(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))))
```
sourceraw docstring

verifying-eventuallycljmacro

(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))))
```
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close