1
- import { fakeAsync , flush , tick } from '@angular/core/testing' ;
1
+ import { fakeAsync , flush , flushMicrotasks , tick } from '@angular/core/testing' ;
2
2
3
3
4
- fdescribe ( " Async Testing Examples" , ( ) => {
4
+ fdescribe ( ' Async Testing Examples' , ( ) => {
5
5
6
-
7
- it ( "Asynchronous test example with Jasmine done()" , ( done :DoneFn ) => {
6
+ it ( 'Asynchronous test example with Jasmine done()' , ( done : DoneFn ) => {
8
7
9
8
let test = false ;
10
9
@@ -20,16 +19,15 @@ fdescribe("Async Testing Examples", () => {
20
19
21
20
} , 1000 ) ;
22
21
23
-
24
-
25
22
} ) ;
26
23
27
24
28
- it ( " Asynchronous test example - setTimeout()" , fakeAsync ( ( ) => {
25
+ it ( ' Asynchronous test example - setTimeout()' , fakeAsync ( ( ) => {
29
26
30
27
let test = false ;
31
28
32
- setTimeout ( ( ) => { } ) ;
29
+ setTimeout ( ( ) => {
30
+ } ) ;
33
31
34
32
setTimeout ( ( ) => {
35
33
@@ -46,6 +44,35 @@ fdescribe("Async Testing Examples", () => {
46
44
} ) ) ;
47
45
48
46
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
+
49
76
} ) ;
50
77
51
78
0 commit comments