Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
test(http): correct response handling in httpResource
Ensure httpResource properly handles the response flow
  • Loading branch information
SkyZeroZx committed Mar 4, 2026
commit 83120839189edcb3b747697f48b58cccc61ddf4b
12 changes: 4 additions & 8 deletions packages/common/http/test/resource_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import {HttpTestingController, provideHttpClientTesting} from '../testing';
import {withHttpTransferCache} from '../src/transfer_cache';
import {HttpClient} from '../src/client';
import {lastValueFrom} from 'rxjs';

describe('httpResource', () => {
beforeEach(() => {
Expand Down Expand Up @@ -424,15 +425,10 @@ describe('httpResource', () => {

it('should synchronously resolve with a cached value from TransferState', async () => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to my review, this test was failing due to the recent changes to the transfer cache, which now behaves asynchronously.
I'm not sure if we should change the test name or if it's correct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was intentional to ensure there's no loading state when pulling data from the transfer cache. #67307

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think it would stay as it is, only keeping the change I made due to the TransferCache update

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thePunderWoman With the latest changes, I think it would be okay to merge, or would we still need to adjust something?

globalThis['ngServerMode'] = true;
let requestResolved = false;
TestBed.inject(HttpClient)
.get('/data')
.subscribe(() => (requestResolved = true));
const req = TestBed.inject(HttpTestingController).expectOne('/data');
req.flush([1, 2, 3]);

expect(requestResolved).toBe(true);

const response = lastValueFrom(TestBed.inject(HttpClient).get('/data'));
TestBed.inject(HttpTestingController).expectOne('/data').flush([1, 2, 3]);
await response;
// Now switch to client mode
globalThis['ngServerMode'] = false;

Expand Down