API Reference

Gomega

A matcher library for Go that pairs with Ginkgo or works with standard tests.

Official Documentation ↗
CompatibilityThis documentation covers version v1.33. Check the official docs for the latest API surface.

Installation

gogo get github.com/onsi/gomega

Methods

Gomega provides Expect with rich matchers and asynchronous Eventually assertions.

Key Features

  • Expressive matchers for values and errors
  • Eventually and Consistently for async
  • Works with Ginkgo or plain testing

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://onsi.github.io/gomega/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:55.363Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

  • Using Gomega with Ginkgo When a Gomega assertion fails, Gomega calls a GomegaFailHandler . (https://onsi.github.io/gomega/)
  • Handling Errors It is a common pattern, in Golang, for functions and methods to return two things - a value and an error. (https://onsi.github.io/gomega/)
  • Assertions about errors on functions with multiple return values can be made as follows (and in a lazy way when not asserting that all other return values are zero values): _ , _ , _ , err := MultipleReturnValuesFunc () Ω ( err ) . (https://onsi.github.io/gomega/)

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://onsi.github.io/gomega/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:55.363Z.

FAQ

When should I use Eventually?
For values that settle asynchronously, such as goroutine results, so the test does not race the change.
How do I match struct fields?
Use MatchFields or the gstruct package to assert selected fields without comparing the whole value.
Can I get a helpful failure message?
Add the optional description argument to Expect or Eventually so failures explain what was being checked.