WithMatcher attaches a matcher to the request. All attached matchers are invoked in the Expect method for a newly created Response. Example: req := NewRequestC(config, "GET", "/path") req.WithMatcher(func (resp *httpexpect.Response) { resp.Header("API-Version").NotEmpty() })
(matcher func(*Response))
| 349 | // resp.Header("API-Version").NotEmpty() |
| 350 | // }) |
| 351 | func (r *Request) WithMatcher(matcher func(*Response)) *Request { |
| 352 | opChain := r.chain.enter("WithMatcher()") |
| 353 | defer opChain.leave() |
| 354 | |
| 355 | r.mu.Lock() |
| 356 | defer r.mu.Unlock() |
| 357 | |
| 358 | if opChain.failed() { |
| 359 | return r |
| 360 | } |
| 361 | |
| 362 | if !r.checkOrder(opChain, "WithMatcher()") { |
| 363 | return r |
| 364 | } |
| 365 | |
| 366 | if matcher == nil { |
| 367 | opChain.fail(AssertionFailure{ |
| 368 | Type: AssertUsage, |
| 369 | Errors: []error{ |
| 370 | errors.New("unexpected nil argument"), |
| 371 | }, |
| 372 | }) |
| 373 | return r |
| 374 | } |
| 375 | |
| 376 | r.matchers = append(r.matchers, matcher) |
| 377 | return r |
| 378 | } |
| 379 | |
| 380 | // WithTransformer attaches a transform to the Request. |
| 381 | // All attachhed transforms are invoked in the Expect methods for |