You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aio/content/guide/testing.md
+18-1Lines changed: 18 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1266,7 +1266,8 @@ You do have to call [tick()](api/core/testing/tick) to advance the (virtual) clo
1266
1266
Calling [tick()](api/core/testing/tick) simulates the passage of time until all pending asynchronous activities finish.
1267
1267
In this case, it waits for the error handler's `setTimeout()`.
1268
1268
1269
-
The [tick()](api/core/testing/tick) function accepts milliseconds as a parameter (defaults to 0 if not provided). The parameter represents how much the virtual clock advances. For example, if you have a `setTimeout(fn, 100)` in a `fakeAsync()` test, you need to use tick(100) to trigger the fn callback.
1269
+
The [tick()](api/core/testing/tick) function accepts milliseconds and tickOptions as parameters, the millisecond (defaults to 0 if not provided) parameter represents how much the virtual clock advances. For example, if you have a `setTimeout(fn, 100)` in a `fakeAsync()` test, you need to use tick(100) to trigger the fn callback. The tickOptions is an optional parameter with a property called processNewMacroTasksSynchronously (defaults is true) represents whether to invoke
1270
+
new generated macro tasks when ticking.
1270
1271
1271
1272
<code-example
1272
1273
path="testing/src/app/demo/async-helper.spec.ts"
@@ -1276,6 +1277,22 @@ The [tick()](api/core/testing/tick) function accepts milliseconds as a parameter
1276
1277
The [tick()](api/core/testing/tick) function is one of the Angular testing utilities that you import with `TestBed`.
1277
1278
It's a companion to `fakeAsync()` and you can only call it within a `fakeAsync()` body.
In this example, we have a new macro task (nested setTimeout), by default, when we `tick`, the setTimeout `outside` and `nested` will both be triggered.
And in some case, we don't want to trigger the new maco task when ticking, we can use `tick(milliseconds, {processNewMacroTasksSynchronously:false})` to not invoke new maco task.
1295
+
1279
1296
#### Comparing dates inside fakeAsync()
1280
1297
1281
1298
`fakeAsync()` simulates passage of time, which allows you to calculate the difference between dates inside `fakeAsync()`.
0 commit comments