|
3 | 3 | ComponentFixture,
|
4 | 4 | fakeAsync,
|
5 | 5 | tick,
|
6 |
| - flush |
| 6 | + flush, |
| 7 | + async |
7 | 8 | } from "@angular/core/testing"; // for integration test
|
8 | 9 | import { HeroDetailComponent } from "./hero-detail.component";
|
9 | 10 | import { ActivatedRoute } from "@angular/router";
|
@@ -52,33 +53,47 @@ describe(`Hero Detail Component`, () => {
|
52 | 53 | ); //assert;
|
53 | 54 | });
|
54 | 55 |
|
55 |
| - it(`should call updateHero when save is called`, done => { |
56 |
| - //now the test will wait until the async code its called |
57 |
| - mockHeroService.updateHero.and.returnValue(of({})); |
| 56 | + // it(`should call updateHero when save is called`, done => { |
| 57 | + // //now the test will wait until the async code its called |
| 58 | + // mockHeroService.updateHero.and.returnValue(of({})); |
58 | 59 |
|
59 |
| - fixture.detectChanges(); //at |
| 60 | + // fixture.detectChanges(); //at |
60 | 61 |
|
61 |
| - fixture.componentInstance.save(); |
| 62 | + // fixture.componentInstance.save(); |
62 | 63 |
|
63 |
| - setTimeout(() => { |
64 |
| - //bacause we set 250 on the heroDeatails deboucen cal function |
65 |
| - expect(mockHeroService.updateHero).toHaveBeenCalled(); |
66 |
| - done(); |
67 |
| - }, 300); |
68 |
| - }); |
| 64 | + // setTimeout(() => { |
| 65 | + // //bacause we set 250 on the heroDeatails deboucen cal function |
| 66 | + // expect(mockHeroService.updateHero).toHaveBeenCalled(); |
| 67 | + // done(); |
| 68 | + // }, 300); |
| 69 | + // }); |
| 70 | + |
| 71 | + // it("should call updateHero when save is called", fakeAsync(() => { |
| 72 | + // //now the test will wait until the async code its called |
| 73 | + // mockHeroService.updateHero.and.returnValue(of({})); |
69 | 74 |
|
70 |
| - it("should call updateHero when save is called", fakeAsync(() => { |
| 75 | + // fixture.detectChanges(); //at |
| 76 | + |
| 77 | + // fixture.componentInstance.save(); |
| 78 | + // //bacause we set 250 on the heroDeatails deboucen cal function |
| 79 | + |
| 80 | + // flush(); //look at the zone to see if there any task waiting |
| 81 | + |
| 82 | + // //tick(250); //control of zone.js can be manipulate the time inside of it thanks to thick |
| 83 | + // expect(mockHeroService.updateHero).toHaveBeenCalled(); |
| 84 | + // })); |
| 85 | + |
| 86 | + it("should call updateHero when save is called", async(() => { |
71 | 87 | //now the test will wait until the async code its called
|
72 | 88 | mockHeroService.updateHero.and.returnValue(of({}));
|
73 | 89 |
|
74 | 90 | fixture.detectChanges(); //at
|
75 | 91 |
|
76 | 92 | fixture.componentInstance.save();
|
77 |
| - //bacause we set 250 on the heroDeatails deboucen cal function |
78 | 93 |
|
79 |
| - flush(); //look at the zone to see if there any task waiting |
80 |
| - |
81 |
| - //tick(250); //control of zone.js can be manipulate the time inside of it thanks to thick |
82 |
| - expect(mockHeroService.updateHero).toHaveBeenCalled(); |
| 94 | + fixture.whenStable().then(() => { |
| 95 | + //checks for promises if they are all resolve |
| 96 | + expect(mockHeroService.updateHero).toHaveBeenCalled(); |
| 97 | + }); |
83 | 98 | }));
|
84 | 99 | });
|
0 commit comments