diff --git a/modules/store/spec/integration_signals.spec.ts b/modules/store/spec/integration_signals.spec.ts index 776727b333..0014542264 100644 --- a/modules/store/spec/integration_signals.spec.ts +++ b/modules/store/spec/integration_signals.spec.ts @@ -12,6 +12,7 @@ import { VisibilityFilters, resetId, } from './fixtures/todos'; +import { computed } from '@angular/core'; interface Todo { id: number; @@ -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); + }); + }); });