mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(common): rename httpResource function in factory (#60022)
As the function in the factory was named `httpResourceRef`, error NG0203 had with the following message: ``` Error: NG0203: httpResourceRef() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with `runInInjectionContext`. Find more at https://angular.dev/errors/NG0203 ``` PR Close #60022
This commit is contained in:
@@ -226,7 +226,7 @@ type ResponseType = 'arraybuffer' | 'blob' | 'json' | 'text';
|
||||
type RawRequestType = (() => string | undefined) | (() => HttpResourceRequest | undefined);
|
||||
|
||||
function makeHttpResourceFn<TRaw>(responseType: ResponseType) {
|
||||
return function httpResourceRef<TResult = TRaw>(
|
||||
return function httpResource<TResult = TRaw>(
|
||||
request: RawRequestType,
|
||||
options?: HttpResourceOptions<TResult, TRaw>,
|
||||
): HttpResourceRef<TResult> {
|
||||
|
||||
@@ -22,6 +22,12 @@ describe('httpResource', () => {
|
||||
TestBed.configureTestingModule({providers: [provideHttpClient(), provideHttpClientTesting()]});
|
||||
});
|
||||
|
||||
it('should throw if used outside injection context', () => {
|
||||
expect(() => httpResource(() => '/data')).toThrowMatching((thrown) =>
|
||||
thrown.message.includes('httpResource() can only be used within an injection context'),
|
||||
);
|
||||
});
|
||||
|
||||
it('should send a basic request', async () => {
|
||||
const backend = TestBed.inject(HttpTestingController);
|
||||
const res = httpResource(() => '/data', {injector: TestBed.inject(Injector)});
|
||||
|
||||
Reference in New Issue
Block a user