MCPcopy Create free account
hub / github.com/gavv/httpexpect / TestExpect_Inheritance

Function TestExpect_Inheritance

expect_test.go:468–546  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

466}
467
468func TestExpect_Inheritance(t *testing.T) {
469 t.Run("reporter", func(t *testing.T) {
470 rootReporter := newMockReporter(t)
471 req2Reporter := newMockReporter(t)
472
473 e := WithConfig(Config{
474 BaseURL: "http://example.com",
475 Client: &mockClient{},
476 Reporter: rootReporter,
477 })
478
479 req1 := e.GET("/")
480 req2 := e.GET("/")
481
482 req2.WithReporter(req2Reporter)
483
484 // So far OK
485 req1.chain.assert(t, success)
486 req2.chain.assert(t, success)
487
488 resp1 := req1.Expect()
489 resp2 := req2.Expect()
490
491 // So far OK
492 resp1.chain.assert(t, success)
493 resp2.chain.assert(t, success)
494
495 // Failure on resp1 should be reported to rootReporter,
496 // which was inherited from config
497 resp1.JSON().Object().Value("foo").chain.assert(t, failure)
498 assert.Equal(t, 1, rootReporter.reportCalled)
499 assert.Equal(t, 0, req2Reporter.reportCalled)
500
501 // Failure on resp2 should be reported to req2Reporter,
502 // which was inherited from req2
503 resp2.JSON().Object().Value("foo").chain.assert(t, failure)
504 assert.Equal(t, 1, rootReporter.reportCalled)
505 assert.Equal(t, 1, req2Reporter.reportCalled)
506 })
507
508 t.Run("assertion handler", func(t *testing.T) {
509 rootHandler := &mockAssertionHandler{}
510 req2Handler := &mockAssertionHandler{}
511
512 e := WithConfig(Config{
513 BaseURL: "http://example.com",
514 Client: &mockClient{},
515 AssertionHandler: rootHandler,
516 })
517
518 req1 := e.GET("/")
519 req2 := e.GET("/")
520
521 req2.WithAssertionHandler(req2Handler)
522
523 // So far OK
524 req1.chain.assert(t, success)
525 req2.chain.assert(t, success)

Callers

nothing calls this directly

Calls 11

newMockReporterFunction · 0.85
WithConfigFunction · 0.85
GETMethod · 0.80
WithReporterMethod · 0.80
assertMethod · 0.80
WithAssertionHandlerMethod · 0.80
ExpectMethod · 0.45
ValueMethod · 0.45
ObjectMethod · 0.45
JSONMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…