Skip to content
Merged
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
16 changes: 8 additions & 8 deletions packages/core/test/resource/params_status_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,19 @@ describe('resource with ResourceParamsStatus', () => {

it('should propagate a different error thrown from params', async () => {
const s = signal<string | Error>('foo');
const res = await actAsync(() =>
const res = await act(() =>
resource({
params: throwStatusAndErrors(s),
loader: async ({params}) => params as string,
injector: TestBed.inject(Injector),
}),
);

await actAsync(() => s.set(new Error('first')));
await act(() => s.set(new Error('first')));
expect(res.status()).toBe('error');
expect(res.error()).toEqual(new Error('first'));

await actAsync(() => s.set(new Error('second')));
await act(() => s.set(new Error('second')));
expect(res.status()).toBe('error');
expect(res.error()).toEqual(new Error('second'));
});
Expand All @@ -142,7 +142,7 @@ describe('resource with ResourceParamsStatus', () => {
const s = signal<string | ResourceParamsStatus>(ResourceParamsStatus.LOADING);
let paramsCount = 0;
let loadCount = 0;
const res = await actAsync(() =>
const res = await act(() =>
resource({
params: () => {
paramsCount++;
Expand All @@ -160,13 +160,13 @@ describe('resource with ResourceParamsStatus', () => {
expect(res.status()).toBe('loading');
expect(paramsCount).toBe(1);

await actAsync(() => unrelated.set(1));
await act(() => unrelated.set(1));

expect(paramsCount).toBe(2);
expect(res.status()).toBe('loading');
expect(loadCount).toBe(0);

await actAsync(() => s.set('foo'));
await act(() => s.set('foo'));
expect(res.status()).toBe('resolved');
expect(loadCount).toBe(1);
});
Expand All @@ -175,7 +175,7 @@ describe('resource with ResourceParamsStatus', () => {
const throwIt = signal(false);
let loads = 0;

const res = await actAsync(() =>
const res = await act(() =>
resource({
params: () => {
if (throwIt()) {
Expand All @@ -194,7 +194,7 @@ describe('resource with ResourceParamsStatus', () => {
expect(res.status()).toBe('idle');
expect(loads).toBe(0);

await actAsync(() => throwIt.set(true));
await act(() => throwIt.set(true));

expect(res.status()).toBe('error');
expect(loads).toBe(0);
Expand Down
10 changes: 5 additions & 5 deletions packages/core/test/resource/resource_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,29 +1044,29 @@ describe('resource', () => {
injector: TestBed.inject(Injector),
});

await timeout();
await flushMicrotasks();
expect(loadCount).toBe(1);
expect(userResource.value()).toBe('user-1-1');

// Updating `routeParams` with a new object that has the same `id` should not re-run the loader
routeParams.set({id: '1', tab: 'orders'});
await timeout();
await flushMicrotasks();
expect(loadCount).toBe(1);
expect(userResource.value()).toBe('user-1-1');

// Even after a manual reload(), a subsequent signal update with the same `id` should not trigger another reload
userResource.reload();
await timeout();
await flushMicrotasks();
expect(loadCount).toBe(2);
expect(userResource.value()).toBe('user-1-2');

routeParams.set({id: '1', tab: 'settings'});
await timeout();
await flushMicrotasks();
expect(loadCount).toBe(2);
expect(userResource.value()).toBe('user-1-2');

routeParams.set({id: '2', tab: 'settings'});
await timeout();
await flushMicrotasks();
expect(loadCount).toBe(3);
expect(userResource.value()).toBe('user-2-3');
});
Expand Down
Loading