JockelzF
JockelzF

Reputation: 433

NgRx Signal Store: How to mock entities?

I'm using an ngrx signal store with the withEntities Feature (https://ngrx.io/guide/signals/signal-store/entity-management), like so:

import { signalStore } from '@ngrx/signals';
import { withEntities } from '@ngrx/signals/entities';

type Todo = {
  id: number;
  text: string;
  completed: boolean;
};

export const TodosStore = signalStore(
  withEntities<Todo>()
);

Now I would like to have component tests, that use a mock state of that store. For a normal ngrx signal store this is well documented (https://ngrx.io/guide/signals/signal-store/testing#native-mocking), but how does it work for withEntities?

  TestBed.configureTestingModule({
    imports: [SomeComponent],
    providers: [
      {
        provide: TodosStore,
        useValue: mock //what to put here?
      },
    ],
  });

Upvotes: 0

Views: 43

Answers (1)

JockelzF
JockelzF

Reputation: 433

Figured it out myself, at least one possible solution:

      useValue: {
        entities: jasmine.createSpy('entities').and.returnValue([
          {
            id: '1',
            text: 'dfsdsffds',
            ...
          }
        ])
      }

Upvotes: 0

Related Questions