Skip to content

Commit

Permalink
test(store): selectSignal immutable state update trigger (#3882)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikezks committed May 8, 2023
1 parent 1ea26f1 commit dfdca6f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions modules/store/spec/integration_signals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
VisibilityFilters,
resetId,
} from './fixtures/todos';
import { computed } from '@angular/core';

interface Todo {
id: number;
Expand Down Expand Up @@ -130,4 +131,30 @@ describe('NgRx and Signals Integration spec', () => {
expect(error).toBeUndefined();
});
});

describe('immutable state integration spec', () => {
it('Store.selectSignal should not trigger on unrelated global state changes', () => {
let todosTriggerCount = 0;

const todos = TestBed.runInInjectionContext(() =>
store.selectSignal((state) => state.todos)
);

const todosTriggerState = TestBed.runInInjectionContext(() =>
computed(() => {
todos();
return ++todosTriggerCount;
})
);

store.dispatch({ type: ADD_TODO, payload: { text: 'first todo' } });
expect(todosTriggerState()).toBe(1);

store.dispatch({
type: SET_VISIBILITY_FILTER,
payload: VisibilityFilters.SHOW_ACTIVE,
});
expect(todosTriggerState()).toBe(1);
});
});
});

0 comments on commit dfdca6f

Please sign in to comment.