Visitar URL original
docs: issue a request in the HTTP interceptor test example by mariella-203 路 Pull Request #71242 路 angular/angular 路 GitHub
Skip to content

docs: issue a request in the HTTP interceptor test example - #71242

Open
mariella-203 wants to merge 1 commit into
angular:mainfrom
mariella-203:docs/http-interceptor-test-request
Open

mariella-203 wants to merge 1 commit into
angular:mainfrom
mariella-203:docs/http-interceptor-test-request

Conversation

@mariella-203

@mariella-203 mariella-203 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Send and subscribe to the request before calling expectOne so the authentication interceptor runs. flush the mock response after checking its header.

Validate the original failure and corrected snippet for functional and DI interceptors with the main-branch HTTP testing backend.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Send and subscribe to the request before calling expectOne so the authentication interceptor runs. Flush the mock response after checking its header.

Validate the original failure and corrected snippet for functional and DI interceptors with the main-branch HTTP testing backend. Check Markdown formatting and confirm the change is limited to one snippet.
@pullapprove
pullapprove Bot requested a review from MarkTechson October 7, 2026 19:45
@angular-robot angular-robot Bot added the area: docs Related to the documentation label Oct 7, 2026
@ngbot ngbot Bot added this to the Backlog milestone Oct 7, 2026
const req = httpTesting.expectOne('/api/config');

expect(req.request.headers.get('X-Authentication-Token')).toEqual(service.getAuthToken());
req.flush({});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would:

const service = TestBed.inject(AuthService);

// Make an HTTP request.
const response = firstValueFrom(http.get('/api/config'));

const req = httpTesting.expectOne('/api/config');

expect(req.request.headers.get('X-Authentication-Token')).toEqual(service.getAuthToken());

in order to:

  • Avoid the empty .subscribe()
  • Drop the req.flush to keep the example more concise since this is just a snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: docs Related to the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants