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
docs: fix docs and associated code snippets for enabling more macro tasks in fakeAsync()
In the `testing` guide, there is a section discussing configuring
`fakeAsync()` to handle more macro tasks (e.g.
`HTMLCanvasElement#toBlob()`).
Previously, the corresponding code snippets (some of which were
hard-coded in the guide) were incorrect/incomplete and the associated
tests were broken. This was discovered while enabling docs examples unit
tests in #34374.
This commit fixes the code snippets and associated tests and ensures the
examples used in the guide come from an example app (i.e. are not
hard-coded).
Note: The docs examples unit tests are currently not run on CI. This
will be fixed in #34374.
@@ -1266,8 +1264,7 @@ You do have to call [tick()](api/core/testing/tick) to advance the (virtual) clo
1266
1264
Calling [tick()](api/core/testing/tick) simulates the passage of time until all pending asynchronous activities finish.
1267
1265
In this case, it waits for the error handler's `setTimeout()`.
1268
1266
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.
1267
+
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 to true) represents whether to invoke new generated macro tasks when ticking.
1271
1268
1272
1269
<code-example
1273
1270
path="testing/src/app/demo/async-helper.spec.ts"
@@ -1331,51 +1328,46 @@ You can also use RxJS scheduler in `fakeAsync()` just like using `setTimeout()`
1331
1328
1332
1329
#### Support more macroTasks
1333
1330
1334
-
By default `fakeAsync()` supports the following `macroTasks`.
1331
+
By default,`fakeAsync()` supports the following macro tasks.
1335
1332
1336
-
- setTimeout
1337
-
- setInterval
1338
-
- requestAnimationFrame
1339
-
- webkitRequestAnimationFrame
1340
-
- mozRequestAnimationFrame
1333
+
-`setTimeout`
1334
+
-`setInterval`
1335
+
-`requestAnimationFrame`
1336
+
-`webkitRequestAnimationFrame`
1337
+
-`mozRequestAnimationFrame`
1341
1338
1342
-
If you run other `macroTask`such as `HTMLCanvasElement.toBlob()`, `Unknown macroTask scheduled in fake async test` error will be thrown.
1339
+
If you run other macro tasks such as `HTMLCanvasElement.toBlob()`, an _"Unknown macroTask scheduled in fake async test"_ error will be thrown.
Note that in order to make the `<canvas>` element Zone.js-aware in your app, you need to import the `zone-patch-canvas` patch (either in `polyfills.ts` or in the specific file that uses `<canvas>`):
1364
+
1365
+
<code-example
1366
+
header="src/polyfills.ts or src/app/shared/canvas.component.ts"
1367
+
path="testing/src/app/shared/canvas.component.ts"
1368
+
region="import-canvas-patch">
1369
+
</code-example>
1370
+
1379
1371
1380
1372
#### Async observables
1381
1373
@@ -3635,7 +3627,7 @@ next to their corresponding helper files.
3635
3627
#### Keep it simple
3636
3628
3637
3629
[Component class testing](#component-class-testing) should be kept very clean and simple.
3638
-
It should test only a single unit. On a first glance, you should be able to understand
3630
+
It should test only a single unit. On a first glance, you should be able to understand
3639
3631
what the test is testing. If it's doing more, then it doesn't belong here.
0 commit comments