Skip to content
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
7 changes: 7 additions & 0 deletions packages/common/http/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ export function provideHttpClient(...features: HttpFeature<HttpFeatureKind>[]):
`Configuration error: found both withXsrfConfiguration() and withNoXsrfProtection() in the same call to provideHttpClient(), which is a contradiction.` :
'');
}

if (featureKinds.has(HttpFeatureKind.RequestsMadeViaParent) && featureKinds.has(HttpFeatureKind.Fetch)) {
throw new Error(
ngDevMode ?
`Configuration error: found both withRequestsMadeViaParent() and withFetch() in the same call to provideHttpClient(), which is a contradiction.` :
'');
}
}

const providers: Provider[] = [
Expand Down
18 changes: 18 additions & 0 deletions packages/common/http/test/provider_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,24 @@ describe('provideHttpClient', () => {
expect(consoleWarnSpy.calls.count()).toBe(0);
});

it('should throw when fetch is used together with withRequestsMadeViaParent()', () => {
TestBed.resetTestingModule();

TestBed.configureTestingModule({
providers: [
provideHttpClient(),
provideHttpClientTesting(),
]
});

expect(() => createEnvironmentInjector(
[provideHttpClient(
withFetch(),
withRequestsMadeViaParent(),
)],
TestBed.inject(EnvironmentInjector))).toThrow();
});

it('should warn during SSR if fetch is not configured', () => {
resetFetchBackendWarningFlag();

Expand Down