Skip to content

Commit 02e8706

Browse files
thediveoonsi
authored andcommitted
docs: Receive(POINTER, MATCHER)
Signed-off-by: thediveo <[email protected]>
1 parent ec1f186 commit 02e8706

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docs/index.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ Finally, as a corollary: it is an error to check whether or not a send-only chan
877877
#### Receive()
878878

879879
```go
880-
Ω(ACTUAL).Should(Receive(<optionalPointer>))
880+
Ω(ACTUAL).Should(Receive(<optionalPointer>, <optionalMatcher>))
881881
```
882882

883883
succeeds if there is a message to be received on actual. Actual must be a channel (and cannot be a send-only channel) -- anything else is an error.
@@ -930,6 +930,14 @@ Eventually(bagelChan).Should(Receive(&receivedBagel))
930930

931931
Of course, this could have been written as `receivedBagel := <-bagelChan` - however using `Receive` makes it easy to avoid hanging the test suite should nothing ever come down the channel. The pointer can point to any variable whose type is assignable from the channel element type, or if the channel type is an interface and the underlying type is assignable to the pointer.
932932

933+
Sometimes, you might need to *grab* the object that *matches* certain criteria:
934+
935+
```go
936+
var receivedBagel Bagel
937+
Eventually(bagelChan).Should(Receive(&receivedBagel, HaveField("Kind", "sesame")))
938+
Ω(receivedBagel.Contents()).Should(ContainElement("cream cheese"))
939+
```
940+
933941
Finally, `Receive` *never* blocks. `Eventually(c).Should(Receive())` repeatedly polls `c` in a non-blocking fashion. That means that you cannot use this pattern to verify that a *non-blocking send* has occurred on the channel - [more details at this GitHub issue](https://github.com/onsi/gomega/issues/82).
934942

935943
#### BeSent(value interface{})

0 commit comments

Comments
 (0)