Commit graph

30 commits

Author SHA1 Message Date
Mansi Shrivastava
7426dbbd56 refactor(common): allow HttpErrorResponse with successful status codes (#61107)
This adds the ability to mock out errors even when successful status codes are returned.

Fixes #26161

PR Close #61107
2025-06-25 17:01:18 +00:00
Andrew Kushnir
3fa7b2b136 refactor(common): convert scripts within packages/common to relative imports (#60623)
This commit updates scripts within `packages/common` to relative imports as a prep work to the upcoming infra updates.

PR Close #60623
2025-04-01 15:58:51 +00:00
Matthieu Riegler
0034ce5583 refactor(http): Don't log fetch warning in tests. (#59049)
Prior to this commit, we were logging the `NOT_USING_FETCH_BACKEND_IN_SSR` error when `provideHttpTestingClient` and `PLATFORM_ID` were provided.

fixes #59028

PR Close #59049
2024-12-05 16:12:55 -08:00
Joey Perrott
9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00
Matthieu Riegler
f914f6a362 feat(migrations): Migration schematics for HttpClientModule (#54020)
This migration will allow developers to migrate the deprecated `HttpClientModule`, `HttpClientJsonpModule` & `HttpClientXsrfModule` to their respective provider functions.

PR Close #54020
2024-04-23 12:12:31 -07:00
Matthieu Riegler
ef665a40a5 refactor(http): Deprecate HttpClientModule & related modules (#54020)
This commit deprecates the `HttpClientModule` and other related http modules. Those can be replaced by provider function only.

Angular is an opinionated framework, feature guidance will help developer choose the recommended way to enable feature (like Http requests here).

Note: This is not an indication of deprecation for `NgModule`. The deprecated module's only purpose here was to define providers. This can be done directly by the provide function pattern.

DEPRECATED: `HttpClientModule`, `HttpClientXsrfModule` and `HttpClientJsonpModule`

As mentionned, those modules can be replaced by provider function only.

PR Close #54020
2024-04-23 12:12:31 -07:00
Andrew Scott
6993146a25 refactor(http): Do not contribute to stability when using provideHttpClientTesting (#54974)
`HttpClient` uses the `PendingTasks` service to contribute to
application stability. This was added in v16 to support SSR without
relying on an infinite `setTimeout` with ZoneJS like it did pre-v16.
Prior to version 16, this was also only done on the server and did not
affect clients or unit tests (28c68f709c).

Today, `PendingTasks` contribute to `ApplicationRef.isStable` but do not
contribute to the stability of `ComponentFixture`. This divergence in
stability behavior was not intended and we plan to make these two
stability indicators the same again, like they were when it was solely
based on the state of the Zone.

By aligning the two behaviors again, this would include all pending
tasks in the stability of fixtures. After investigation, this seems
likely to be a pretty large breaking change. Tests appear to quite often use
`await fixture.whenStable` when there are unfinished requests that have
not been mocked or flushed.

This change prevents request in `HttpClient` from contributing to
stability through the `PendingTasks` automatically but only when using
`HttpClientTesting`. In this scenario, requests need to be expected and
flushed manually for them to resolve. When the test backend and controllers
aren't used, requests should resolve on their own so `await fixture.whenStable`
shouldn't be particularly affected or problematic.

PR Close #54974
2024-04-10 09:27:40 -07:00
Joey Perrott
0460a9dfaf refactor: migrate common to prettier formatting (#54150)
Migrate formatting to prettier for common from clang-format

PR Close #54150
2024-01-30 16:08:07 +00:00
Matthieu Riegler
89ab1c18a1 refactor(common): Use Nullish coalescing assignment when possible. (#53931)
Inspired by #53923, lets simplify code when possible.

PR Close #53931
2024-01-26 16:58:36 +00:00
alkavats1
66824b7715 refactor: removed the unused declaration in the import statement (#50616)
ngmodule and httpclient modeule is removed from the provider.ts file from the import statement

PR Close #50616
2023-06-22 09:39:58 -07:00
Alex Rickabaugh
84d0d33c35 feat(http): introduce provideHttpClientTesting provider function (#47502)
This commit introduces the `provideHttpClientTesting()` function as an
alternative to the `HttpClientTestingModule` (in fact, the NgModule is
converted internally to just use the new provider function).

PR Close #47502
2022-10-06 19:02:45 +00:00
JoostK
a2cbffc06f fix(common): include query parameters for open HTTP requests in verify (#44917)
When `HttpTestingController.verify` is used to verify that there are not open,
unexpected requests it would throw an error with the method and URL of all pending
requests, excluding the query parameters. This is confusing, as e.g. `expectOne`
matches a URL including its query parameters and `expectOne` does include the
query parameters when it reports when no request could be matched.

This commit changes the error that is reported by `verify` to include the query
parameters.

Closes #19974

PR Close #44917
2022-02-01 21:41:43 +00:00
Paul Gschwendtner
489cf42cd0 fix(common): incorrect error type for XHR errors in TestRequest (#36082)
Currently the `HttpClient` always wraps errors from XHR requests, but
the underlying errors are always of type `ProgressEvent`, or don't have
a native error if the status code is just indicating failure (e.g. 404).

This behavior does not match in the `TestRequest` class provided by
`@angular/common/http/testing` where errors are considered being
of type `ErrorEvent`. This is incorrect because `ErrorEvent`s provide
information for errors in scripts or files which are evaluated. Since
the `HttpClient` never evaluates scripts/files, and also since XHR requests
clearly are documented to emit `ProgressEvent`'s, we should change the
`TestSupport` to retrieve such `ProgressEvent`'s instead of incompatible
objects of type `ErrorEvent`.

In favor of having a deprecation period, we keep supporting `ErrorEvent`
in the `TestRequest.error` signature. Eventually, we can remove this
signature in the future.

Resources:
  * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/error_event
  * https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent
  * https://xhr.spec.whatwg.org/#event-xhr-errpr

Related to: https://github.com/angular/angular/issues/34748.

DEPRECATED: `TestRequest` from `@angular/common/http/testing` no longer
accepts `ErrorEvent` when simulating XHR errors. Instead instances of
`ProgressEvent` should be passed, matching with the native browser behavior.

PR Close #36082
2021-11-19 21:26:52 +00:00
Quentin Focheux
baadd109aa test(http): use HttpStatusCode enum in tests (#23548)
Now that we have introduced human-readable http status codes,
we can use it in our tests to improve clarity.

PR Close #23548
2021-01-28 09:10:48 -08:00
Ajit Singh
3c474ecf56 fix(common): add boolean to valid json for testing (#37893)
boolean is a valid json but at present we cannot test Http request using boolean added support for boolean requests

Fixes #20690

PR Close #37893
2020-10-05 17:07:41 -07:00
Joey Perrott
d1ea1f4c7f build: update license headers to reference Google LLC (#37205)
Update the license headers throughout the repository to reference Google LLC
rather than Google Inc, for the required license headers.

PR Close #37205
2020-05-26 14:26:58 -04:00
Joey Perrott
698b0288be build: reformat repo to new clang@1.4.0 (#36613)
PR Close #36613
2020-04-14 12:08:36 -07:00
cexbrayat
115b7e42c6 fix(common): http/testing expectOne lists the received requests if no matches (#27005)
Fixes #18013

Previously it was hard to debug an `expectOne` if the request had no match, as the error message was:

    Expected one matching request for criteria "Match URL: /some-url?query=hello", found none.

This commit adds a bit more info to the error, by listing the actual requests received:

    Expected one matching request for criteria "Match URL: /some-url?query=hello", found none. Requests received are: POST /some-url?query=world.

PR Close #27005
2020-01-31 13:13:37 -08:00
Dave
76110d71d3 docs(http): add information about body content type to flush method for testing (#29214)
PR Close #29214
2019-04-01 11:03:49 -07:00
Pete Bacon Darwin
0918adf39d docs: common with @publicApi tags (#26595)
PR Close #26595
2018-10-19 14:35:53 -07:00
Pete Bacon Darwin
4b96a58c5a docs: remove all deprecated @stable jsdoc tags (#23210)
These are no longer needed as stable docs are computed as those that
do not have `@experimental` or `@deprecated` tags.

PR Close #23210
2018-04-10 21:49:32 -07:00
Igor Minar
b43f8bc7d3 feat(core): upgrade rxjs to 6.0.0-alpha.4 (#22573)
PR Close #22573
2018-03-19 21:51:51 -07:00
Alex Rickabaugh
8b14488827 fix(common): don't convert null to a string when flushing a mock request (#21417)
A bug in TestRequest caused null response bodies to be stringified. This
change causes null to be treated faithfully.

Fixes #20744

PR Close #21417
2018-02-01 08:32:43 -08:00
Alex Rickabaugh
72c7b6edea feat: deprecate @angular/http in favor of @angular/common/http (#18906)
As of 5.0, @angular/http is deprecated. @angular/common/http will
be the official HTTP API in Angular going forward.

PR Close #18906
2017-08-28 18:46:58 -05:00
Victor Berchet
9479a106bb build: enable TSLint on the packages folder 2017-07-31 15:47:57 -07:00
jnizet
5c62e300e1 fix(common): send flushed body as error instead of null
fix #18181
2017-07-18 10:57:51 -07:00
Alex Rickabaugh
18559897a0 fix(common): document HttpClient, fixing a few other issues 2017-07-13 14:58:33 -07:00
Jason Aden
09f1609f81 style(http): fix linting error in http/testing (#18002) 2017-07-07 17:02:07 -07:00
Alex Rickabaugh
c81ad9d19d feat(common): two missing features in HttpClient (#17996)
- Add params to HttpRequest API
- Add optional description to testing APIs
2017-07-07 14:56:36 -07:00
Alex Rickabaugh
37797e2b4e feat(common): new HttpClient API
HttpClient is an evolution of the existing Angular HTTP API, which exists
alongside of it in a separate package, @angular/common/http. This structure
ensures that existing codebases can slowly migrate to the new API.

The new API improves significantly on the ergonomics and features of the legacy
API. A partial list of new features includes:

* Typed, synchronous response body access, including support for JSON body types
* JSON is an assumed default and no longer needs to be explicitly parsed
* Interceptors allow middleware logic to be inserted into the pipeline
* Immutable request/response objects
* Progress events for both request upload and response download
* Post-request verification & flush based testing framework
2017-07-07 12:09:32 -07:00