|
8 | 8 |
|
9 | 9 | import {ApplicationRef, Injector, signal} from '@angular/core';
|
10 | 10 | import {TestBed} from '@angular/core/testing';
|
11 |
| -import {HttpEventType, provideHttpClient, httpResource} from '@angular/common/http'; |
| 11 | +import { |
| 12 | + HttpEventType, |
| 13 | + provideHttpClient, |
| 14 | + httpResource, |
| 15 | + HttpContext, |
| 16 | + HttpContextToken, |
| 17 | +} from '@angular/common/http'; |
12 | 18 | import {HttpTestingController, provideHttpClientTesting} from '@angular/common/http/testing';
|
13 | 19 |
|
14 | 20 | describe('httpResource', () => {
|
@@ -145,6 +151,40 @@ describe('httpResource', () => {
|
145 | 151 | expect(res.value()).toEqual([]);
|
146 | 152 | });
|
147 | 153 |
|
| 154 | + it('should pass all request parameters', () => { |
| 155 | + const backend = TestBed.inject(HttpTestingController); |
| 156 | + |
| 157 | + const CTX_TOKEN = new HttpContextToken(() => 'value'); |
| 158 | + const res = httpResource( |
| 159 | + () => ({ |
| 160 | + url: '/data', |
| 161 | + params: { |
| 162 | + 'fast': 'yes', |
| 163 | + }, |
| 164 | + responseType: 'text', // This one is not overwritten (and no excess property check from ts) |
| 165 | + headers: { |
| 166 | + 'X-Tag': 'alpha,beta', |
| 167 | + }, |
| 168 | + reportProgress: true, |
| 169 | + context: new HttpContext().set(CTX_TOKEN, 'bar'), |
| 170 | + withCredentials: true, |
| 171 | + transferCache: {includeHeaders: ['Y-Tag']}, |
| 172 | + }), |
| 173 | + { |
| 174 | + injector: TestBed.inject(Injector), |
| 175 | + }, |
| 176 | + ); |
| 177 | + TestBed.flushEffects(); |
| 178 | + |
| 179 | + const req = TestBed.inject(HttpTestingController).expectOne('/data?fast=yes'); |
| 180 | + expect(req.request.headers.get('X-Tag')).toEqual('alpha,beta'); |
| 181 | + expect(req.request.responseType).toEqual('json'); |
| 182 | + expect(req.request.withCredentials).toEqual(true); |
| 183 | + expect(req.request.context.get(CTX_TOKEN)).toEqual('bar'); |
| 184 | + expect(req.request.reportProgress).toEqual(true); |
| 185 | + expect(req.request.transferCache).toEqual({includeHeaders: ['Y-Tag']}); |
| 186 | + }); |
| 187 | + |
148 | 188 | it('should allow mapping data to an arbitrary type', async () => {
|
149 | 189 | const backend = TestBed.inject(HttpTestingController);
|
150 | 190 | const res = httpResource(
|
|
0 commit comments