Skip to content

Commit 047bba9

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

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,27 @@ describe('HeroService', () => {
8585
it('should not like a hero because no votes', async(() => {
8686
localStorage.setItem('votes', String(AppConfig.votesLimit));
8787
expect(heroService.checkIfUserCanVote()).toBe(false);
88-
heroService.like(newHeroCreated).subscribe(() => {
89-
}, (error) => {
90-
expect(error).toBe('maximum votes');
88+
heroService.createHero({
89+
'name': 'test',
90+
'alterEgo': 'test'
91+
}).subscribe((hero) => {
92+
heroService.like(hero).subscribe(() => {
93+
}, (error) => {
94+
expect(error).toBe('maximum votes');
95+
});
9196
});
9297
}));
9398

9499
it('should like a hero', async(() => {
95100
localStorage.setItem('votes', String(0));
96101
expect(heroService.checkIfUserCanVote()).toBe(true);
97-
heroService.like(newHeroCreated).subscribe((response) => {
98-
expect(response).toEqual({});
102+
heroService.createHero({
103+
'name': 'test',
104+
'alterEgo': 'test'
105+
}).subscribe((hero) => {
106+
heroService.like(hero).subscribe((response) => {
107+
expect(response).toEqual({});
108+
});
99109
});
100110
}));
101111

0 commit comments

Comments
 (0)