8000 fix(common): rename httpResource function in factory by cexbrayat · Pull Request #60022 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

fix(common): rename httpResource function in factory #60022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/common/http/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
6 changes: 6 additions & 0 deletions packages/common/http/test/resource_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)});
Expand Down
0