Skip to content

Commit 02a37d8

Browse files
IsmaestroIsmael Ramos
authored andcommitted
fix(hero service): solve an async problem with the creation of the test hero
1 parent 047bba9 commit 02a37d8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/app/heroes/shared/hero.service.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {ErrorObservable} from 'rxjs/observable/ErrorObservable';
99

1010
describe('HeroService', () => {
1111
let heroService;
12-
let newHeroCreated;
1312

1413
beforeEach(() => {
1514
TestBed.configureTestingModule({
@@ -77,7 +76,6 @@ describe('HeroService', () => {
7776
'name': 'test',
7877
'alterEgo': 'test'
7978
}).subscribe((hero) => {
80-
newHeroCreated = hero;
8179
expect(hero.id).not.toBeNull();
8280
});
8381
}));
@@ -110,8 +108,13 @@ describe('HeroService', () => {
110108
}));
111109

112110
it('should delete a hero', async(() => {
113-
heroService.deleteHeroById(newHeroCreated.id).subscribe((response) => {
114-
expect(response).toEqual({});
111+
heroService.createHero({
112+
'name': 'test',
113+
'alterEgo': 'test'
114+
}).subscribe((hero) => {
115+
heroService.deleteHeroById(hero.id).subscribe((response) => {
116+
expect(response).toEqual({});
117+
});
115118
});
116119
}));
117120
});

0 commit comments

Comments
 (0)