Skip to content

Commit

Permalink
document HaveValue matcher (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
thediveo committed Dec 15, 2021
1 parent 1ca09a6 commit 955b6ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions _includes/gomega_sidebar.html
Expand Up @@ -201,6 +201,15 @@ <h2>
</ul>
</li>

<li>
<a href="#working-with-values">Working with Values</a>
<ul class="nav">
<li>
<a href="#havevaluematcher-typesgomegamatcher"><code>HaveValue(...)</code></a>
</li>
</ul>
</li>

<li>
<a href="#working-with-http-responses">Working with HTTP responses</a>
<ul class="nav">
Expand Down
20 changes: 20 additions & 0 deletions index.md
Expand Up @@ -1121,6 +1121,26 @@ There are six supported comparators:

Any other comparator is an error.

### Working with Values

#### HaveValue(matcher types.GomegaMatcher)

`HaveValue` applies `MATCHER` to the value that results from dereferencing `ACTUAL` in case of a pointer or an interface, or otherwise `ACTUAL` itself. Pointers and interfaces are dereferenced multiple times as necessary, with a limit of at most 31 dereferences.

```go
Expect(ACTUAL).To(HaveValue(MATCHER))
```

For instance:

```go
i := 42
Expect(&i).To(HaveValue(Equal(42)))
Expect(i).To(HaveValue(Equal(42)))
```

`HaveValue` can be used, for instance, in tests and custom matchers where the it doesn't matter (as opposed to `PointTo`) if a value first needs to be dereferenced or not. This is especially useful to custom matchers that are to be used in mixed contexts of pointers as well as non-pointers.

### Working with HTTP responses

#### HaveHTTPStatus(expected interface{})
Expand Down

0 comments on commit 955b6ff

Please sign in to comment.