Skip to content

Commit db10855

Browse files
author
Your Name
committed
Angular Testing Course
1 parent bbec452 commit db10855

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

src/app/courses/home/async-examples.spec.ts

+35-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import {fakeAsync, flush, tick} from '@angular/core/testing';
1+
import {fakeAsync, flush, flushMicrotasks, tick} from '@angular/core/testing';
22

33

4-
fdescribe("Async Testing Examples", () => {
4+
fdescribe('Async Testing Examples', () => {
55

6-
7-
it("Asynchronous test example with Jasmine done()", (done:DoneFn) => {
6+
it('Asynchronous test example with Jasmine done()', (done: DoneFn) => {
87

98
let test = false;
109

@@ -20,16 +19,15 @@ fdescribe("Async Testing Examples", () => {
2019

2120
}, 1000);
2221

23-
24-
2522
});
2623

2724

28-
it("Asynchronous test example - setTimeout()", fakeAsync(() => {
25+
it('Asynchronous test example - setTimeout()', fakeAsync(() => {
2926

3027
let test = false;
3128

32-
setTimeout(() => {});
29+
setTimeout(() => {
30+
});
3331

3432
setTimeout(() => {
3533

@@ -46,6 +44,35 @@ fdescribe("Async Testing Examples", () => {
4644
}));
4745

4846

47+
fit('Asynchronous test example - plain Promise', fakeAsync(() => {
48+
49+
let test = false;
50+
51+
console.log('Creating promise');
52+
53+
Promise.resolve().then(() => {
54+
55+
console.log('Promise first then() evaluated successfully');
56+
57+
return Promise.resolve();
58+
})
59+
.then(() => {
60+
61+
console.log('Promise second then() evaluated successfully');
62+
63+
test = true;
64+
65+
});
66+
67+
flushMicrotasks();
68+
69+
console.log('Running test assertions');
70+
71+
expect(test).toBeTruthy();
72+
73+
}));
74+
75+
4976
});
5077

5178

0 commit comments

Comments
 (0)