Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
timkindberg authored Mar 7, 2021
1 parent ea49d39 commit 22754ea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,16 @@ expect(result).toEqual('yay!')
```

#### Supports function matchers:

Just wrap any regular function (cannot be a jest mock or spy!) with `when`.

The function will receive the arg and will be considered a match if the function returns true.

It works with both calledWith and expectCalledWith.

```javascript
const allValuesTrue = (arg) => Object.values(arg).every(Boolean)
const numberDivisibleBy3 = (arg) => arg % 3 === 0
const allValuesTrue = when((arg) => Object.values(arg).every(Boolean))
const numberDivisibleBy3 = when((arg) => arg % 3 === 0)

when(fn)
.calledWith(allValuesTrue, numberDivisibleBy3)
Expand Down

0 comments on commit 22754ea

Please sign in to comment.