@@ -4,11 +4,13 @@ import { firstValueFrom, map, of, Subject } from 'rxjs';
44import { todo } from '../todo/todo.model' ;
55import { TodoComponent } from './todo.component' ;
66import { ServiceTodo } from './todo.service' ;
7+ import { TodoStore } from './todo.store' ;
78
89describe ( 'TodoComponent' , ( ) => {
910 let fixture : ComponentFixture < TodoComponent > ;
1011 let component : TodoComponent ;
1112 let todosSubject : Subject < todo [ ] > ;
13+ let store : TodoStore ;
1214
1315 // Mock data for todos
1416 const todosMock : todo [ ] = [
@@ -35,6 +37,8 @@ describe('TodoComponent', () => {
3537
3638 fixture = TestBed . createComponent ( TodoComponent ) ;
3739 component = fixture . componentInstance ;
40+ // inject the store after TestBed
41+ store = TestBed . inject ( TodoStore ) ;
3842 } ) ;
3943 // ---- Test 1: spinner is shown while loading ----
4044 it ( 'should show spinner while loading' , ( ) => {
@@ -52,7 +56,7 @@ describe('TodoComponent', () => {
5256 fixture . detectChanges ( ) ;
5357
5458 const todosLength = await firstValueFrom (
55- component . todos$ . pipe ( map ( ( todos ) => todos . length ) ) ,
59+ store . todos$ . pipe ( map ( ( todos ) => todos . length ) ) ,
5660 ) ;
5761 expect ( todosLength ) . toBe ( 2 ) ;
5862
@@ -68,18 +72,16 @@ describe('TodoComponent', () => {
6872 await fixture . whenStable ( ) ;
6973 fixture . detectChanges ( ) ;
7074
71- const firstTodo = ( await firstValueFrom ( component . todos$ ) ) [ 0 ] ;
75+ const firstTodo = ( await firstValueFrom ( store . todos$ ) ) [ 0 ] ;
7276 component . delete ( firstTodo ) ;
7377 fixture . detectChanges ( ) ;
7478
7579 const todosLength = await firstValueFrom (
76- component . todos$ . pipe ( map ( ( todos ) => todos . length ) ) ,
80+ store . todos$ . pipe ( map ( ( todos ) => todos . length ) ) ,
7781 ) ;
7882 expect ( todosLength ) . toBe ( 1 ) ;
7983 expect (
80- ( await firstValueFrom ( component . todos$ ) ) . find (
81- ( t ) => t . id === firstTodo . id ,
82- ) ,
84+ ( await firstValueFrom ( store . todos$ ) ) . find ( ( t ) => t . id === firstTodo . id ) ,
8385 ) . toBeUndefined ( ) ;
8486 expect ( serviceMock . deleteTodo ) . toHaveBeenCalledWith ( firstTodo ) ;
8587 } ) ;
0 commit comments