Skip to content

Commit

Permalink
fixes issue #600 (#606)
Browse files Browse the repository at this point in the history
- improves documentation for HaveValue with respect to nil and negation.
  • Loading branch information
thediveo authored Nov 12, 2022
1 parent 3eef0d7 commit 808d192
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ Any other comparator is an error.

#### 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.
`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. It will fail if the pointer value is `nil`:

```go
Expect(ACTUAL).To(HaveValue(MATCHER))
Expand All @@ -1372,6 +1372,12 @@ 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.

Please note that negating the outcome of `HaveValue(nil)` won't suppress any error; for instance, in order to assert not having a specific value while still accepting `nil` the following matcher expression might be used:

```go
Or(BeNil(), Not(HaveValue(...)))
```

### Working with HTTP responses

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

0 comments on commit 808d192

Please sign in to comment.