Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
066daef
feat: widen `withResource` to `Resource` beyond `ResourceRef`
michael-small Apr 24, 2026
1046fcf
chore: test resource reload exposure
michael-small Apr 24, 2026
598893c
chore: un-export internal widened resource type
michael-small Apr 24, 2026
b94e490
chore: refactor to conditionally enable resource patching
michael-small May 4, 2026
f21f8ef
chore: condense `isResourceXYZ` functionality
michael-small May 30, 2026
1aaedd8
chore: remove `HttpResourceRefResult`
michael-small May 30, 2026
43ec3b8
chore: remove httpResource specifics
michael-small May 30, 2026
db2f3f6
chore: wip arbitrary signal props in withResource
michael-small Jun 5, 2026
9e5f1af
chore: simplify `withRes` , make union an intersection
michael-small Jun 6, 2026
bc88bcb
chore: re-order new `withResource` tests by category
michael-small Jun 6, 2026
44e7b81
chore: test custom resource properties cannot override props
michael-small Jun 6, 2026
60a1f57
chore: test combo of unnamed + named custom resources + writability
michael-small Jun 6, 2026
17915d8
chore: add extra props write check tests
michael-small Jun 6, 2026
3188dd2
chore: rename helpers for extended resources
michael-small Jun 6, 2026
073865e
chore: add entityResource snapshot support, lacking conditional addEn…
michael-small Jun 1, 2026
0d44245
chore: wip resource snapshots for `withEntityResource`
michael-small Jun 3, 2026
31b5a9d
chore: add test for named snapshot resources in `withEntityResource`
michael-small Jun 3, 2026
7e279d4
chore: fix `withEntityResource` after `withResource` rebase
michael-small Jun 6, 2026
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
94 changes: 94 additions & 0 deletions libs/ngrx-toolkit/src/lib/with-entity-resources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
setAllEntities,
} from '@ngrx/signals/entities';
import { withEntityResources } from './with-entity-resources';
import { withPreviousValue } from './with-resource/tests/util/snapshot';

type Todo = { id: number; title: string; completed: boolean };
const wait = (ms = 0) => new Promise((r) => setTimeout(r, ms));
Expand Down Expand Up @@ -199,6 +200,99 @@ describe('withEntityResources', () => {
]);
});

it('does not support setAllEntities/addEntity/removeEntity for unnamed which are of type Resource', async () => {
const Store = signalStore(
{ providedIn: 'root', protectedState: false },
withEntityResources(() =>
withPreviousValue(
resource({
loader: () => Promise.resolve([] as Todo[]),
defaultValue: [],
}),
),
),
);
const store = TestBed.inject(Store);

await wait();

const invalidSetAll = () =>
patchState(
store,
// @ts-expect-error Resources which are of type Resource should not support entity updaters
setAllEntities([
{ id: 1, title: 'A', completed: false },
{ id: 2, title: 'B', completed: true },
] as Todo[]),
);

const invalidAdd = () =>
patchState(
store,
// @ts-expect-error Resources which are of type Resource should not support entity updaters
addEntity({ id: 3, title: 'C', completed: false } as Todo),
);

// @ts-expect-error Resources which are of type Resource should not support entity updaters
const invalidRemove = () => patchState(store, removeEntity(2));

expect(invalidSetAll).toBeDefined();
expect(invalidAdd).toBeDefined();
expect(invalidRemove).toBeDefined();
expect(store.ids()).toEqual([]);
expect(store.entities()).toEqual([]);
});

it('does not support setAllEntities/addEntity/removeEntity for named which are of type Resource', async () => {
const Store = signalStore(
{ providedIn: 'root', protectedState: false },
withEntityResources(() => ({
todos: withPreviousValue(
resource({
loader: () => Promise.resolve([] as Todo[]),
defaultValue: [],
}),
),
})),
);

const store = TestBed.inject(Store);

await wait();

const invalidSetAll = () =>
patchState(
store,
// @ts-expect-error Resources which are of type Resource should not support entity updaters
setAllEntities(
[
{ id: 1, title: 'A', completed: false },
{ id: 2, title: 'B', completed: true },
] as Todo[],
{ collection: 'todos' },
),
);

const invalidAdd = () =>
patchState(
store,
// @ts-expect-error Resources which are of type Resource should not support entity updaters
addEntity({ id: 3, title: 'C', completed: false } as Todo, {
collection: 'todos',
}),
);

const invalidRemove = () =>
// @ts-expect-error Resources which are of type Resource should not support entity updaters
patchState(store, removeEntity(2, { collection: 'todos' }));

expect(invalidSetAll).toBeDefined();
expect(invalidAdd).toBeDefined();
expect(invalidRemove).toBeDefined();
expect(store.todosIds()).toEqual([]);
expect(store.todosEntities()).toEqual([]);
});

it('supports setAllEntities/addEntity/removeEntity for named', async () => {
const Store = signalStore(
{ providedIn: 'root', protectedState: false },
Expand Down
Loading
Loading