@@ -28,7 +28,7 @@ describe('withDevtools / renaming', () => {
2828 TestBed . inject ( Store ) ;
2929 runInInjectionContext ( childContext , ( ) => inject ( Store ) ) ;
3030
31- TestBed . flushEffects ( ) ;
31+ TestBed . tick ( ) ;
3232
3333 expect ( sendSpy ) . toHaveBeenLastCalledWith (
3434 { type : 'Store Update' } ,
@@ -51,7 +51,7 @@ describe('withDevtools / renaming', () => {
5151 const childContext2 = createEnvironmentInjector ( [ Store ] , envInjector ) ;
5252
5353 runInInjectionContext ( childContext1 , ( ) => inject ( Store ) ) ;
54- TestBed . flushEffects ( ) ;
54+ TestBed . tick ( ) ;
5555 childContext1 . destroy ( ) ;
5656
5757 expect ( sendSpy . mock . calls ) . toEqual ( [
@@ -64,7 +64,7 @@ describe('withDevtools / renaming', () => {
6464 ] ) ;
6565
6666 runInInjectionContext ( childContext2 , ( ) => inject ( Store ) ) ;
67- TestBed . flushEffects ( ) ;
67+ TestBed . tick ( ) ;
6868 expect ( sendSpy . mock . calls ) . toEqual ( [
6969 [
7070 { type : 'Store Update' } ,
@@ -113,7 +113,7 @@ Enable automatic indexing via withDevTools('flights', { indexNames: true }), or
113113 signalStore ( { providedIn : 'root' } , withDevtools ( 'flights' ) ) ,
114114 ) ;
115115
116- TestBed . flushEffects ( ) ;
116+ TestBed . tick ( ) ;
117117 expect ( sendSpy . mock . calls ) . toEqual ( [
118118 [
119119 { type : 'Store Update' } ,
@@ -169,7 +169,7 @@ Enable automatic indexing via withDevTools('flights', { indexNames: true }), or
169169
170170 const store = TestBed . inject ( Store ) ;
171171 renameDevtoolsName ( store , 'flights' ) ;
172- TestBed . flushEffects ( ) ;
172+ TestBed . tick ( ) ;
173173
174174 expect ( sendSpy ) . toHaveBeenCalledWith (
175175 { type : 'Store Update' } ,
@@ -192,7 +192,7 @@ Enable automatic indexing via withDevTools('flights', { indexNames: true }), or
192192 ) ;
193193 TestBed . inject ( Store1 ) ;
194194 const store = TestBed . inject ( Store2 ) ;
195- TestBed . flushEffects ( ) ;
195+ TestBed . tick ( ) ;
196196
197197 expect ( ( ) => renameDevtoolsName ( store , 'shop' ) ) . toThrow (
198198 'NgRx Toolkit/DevTools: cannot rename from mall to shop. shop is already assigned to another SignalStore instance.' ,
@@ -212,5 +212,33 @@ Enable automatic indexing via withDevTools('flights', { indexNames: true }), or
212212 "Devtools extensions haven't been added to this store." ,
213213 ) ;
214214 } ) ;
215+
216+ it ( 'should ignore rename after the store has been destroyed' , ( ) => {
217+ const { sendSpy } = setupExtensions ( ) ;
218+
219+ const Store = signalStore (
220+ withDevtools ( 'flight' ) ,
221+ withState ( { name : 'Product' , price : 10.5 } ) ,
222+ ) ;
223+
224+ const childContext = createEnvironmentInjector (
225+ [ Store ] ,
226+ TestBed . inject ( EnvironmentInjector ) ,
227+ ) ;
228+
229+ const store = childContext . get ( Store ) ;
230+ TestBed . tick ( ) ;
231+
232+ expect ( sendSpy ) . toHaveBeenCalledWith (
233+ { type : 'Store Update' } ,
234+ { flight : { name : 'Product' , price : 10.5 } } ,
235+ ) ;
236+
237+ childContext . destroy ( ) ;
238+ TestBed . tick ( ) ;
239+
240+ // Previously this could throw; now it is a no-op
241+ expect ( ( ) => renameDevtoolsName ( store , 'flights' ) ) . not . toThrow ( ) ;
242+ } ) ;
215243 } ) ;
216244} ) ;
0 commit comments