docs(aio): Testing example app doesn't work since Angular 8
See original GitHub issueš bug report
Is this a regression?
Yes, it wasnāt present in the latest 7 release (see below)
Description
https://angular.io/guide/testing#support-more-macrotasks describes a way to support more macro tasks, the Canvas example is even used in the sample app that you can download at the top of that same page (source code: https://github.com/angular/angular/blob/master/aio/content/examples/testing/src/app/shared/canvas.component.spec.ts).
I noticed that the example app doesnāt allow to run ng test
(due to missing tsconfig file), so I was working on fixing that in order to send in PR to patch it. Once I managed to run ng test
successfully (as in: the tests are extecuted), I noticed that 3 tests failed. I fixed 2 of them (we can discuss the reasons of their failure in the PR once itās up as I think itās unrelated to what Iāll be describing here), but I canāt seem to resolve the 3th test (which I will describe in the reproduction steps below). I noticed that the code to support the macro tasks isnāt working properly anymore.
Iām not sure this is an issue with Angular or an issue with ZoneJS. Maybe itās not even an issue and we can fix this easily by updating the docsā tests. In that case Iāll be happy to fix it as part of the PR Iām finishing.
As I noticed @JiaLiPassion created this test initially (https://github.com/angular/angular/pull/21669), and, if I remember correctly, also added this functionality into zonejs, I wanted to check if you might have any idea what has been changed in zonejs that would break this test?
š¬ Minimal Reproduction (issue in the docs)
- Open the Angular repo locally
- checkout master
- cd into aio and run
yarn build
- cd into
aio/content/examples/testing
and runyarn test
3 tests should fail. You can ignore the No test scheduler initialized
for now, Iāve managed to resolve this locally by patching the exampleZipper but this issue is only about the one thatās failing with the following message:
chrome 74.0.3729 (Linux 0.0.0) CanvasComponent should be able to generate blob data from canvas FAILED
Error: Expected undefined to be greater than 0.
at <Jasmine>
at UserContext.<anonymous> (src/app/shared/canvas.component.spec.ts:24:26)
at UserContext.<anonymous> (home/frederik/Development/github/frederikprijck/angular/aio/tools/examples/shared/node_modules/zone.js/dist/zone-testing.js:1493:1)
at ZoneDelegate.invoke (home/frederik/Development/github/frederikprijck/angular/aio/tools/examples/shared/node_modules/zone.js/dist/zone-evergreen.js:359:1)
š¬ Minimal Reproduction (underlying issue isolated from the docs)
As it was easier for me to swap dependency versions to find the issue, I isolated the issue in an empty cli project:
- Create a new @angular/cli 8 project
- Add this component https://github.com/angular/angular/blob/master/aio/content/examples/testing/src/app/shared/canvas.component.ts and this test https://github.com/angular/angular/blob/master/aio/content/examples/testing/src/app/shared/canvas.component.spec.ts to the project
- run
ng test
The tests should fail with:
chrome 74.0.3729 (Linux 0.0.0) CanvasComponent should be able to generate blob data from canvas FAILED
Error: Expected undefined to be greater than 0.
at <Jasmine>
at UserContext.<anonymous> (src/app/shared/canvas.component.spec.ts:24:26)
at UserContext.<anonymous> (home/frederik/Development/github/frederikprijck/angular/aio/tools/examples/shared/node_modules/zone.js/dist/zone-testing.js:1493:1)
at ZoneDelegate.invoke (home/frederik/Development/github/frederikprijck/angular/aio/tools/examples/shared/node_modules/zone.js/dist/zone-evergreen.js:359:1)
If we do the same, but for an @angular/cli 7 project, the test works fine.
Once we upgrade zone
to 0.9.1
(which is the version used when using @angular/cli
8) in an Angular 7 project, the tests fail.
Itās also broken with zone.js 0.9.0
but works fine with 0.8.29
.
This might be a regression in zonejs, however Iām not that familiar with zonejs so I was hoping to hear @JiaLiPassion 's opinion on this.
š„ Exception or Error
Test is not succeeding.
š Your Environment
Iāve tested this with Angular 7 and 8, on Linux (Elementary OS) and Windows 10.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
@frederikprijck, sure I will check it.
@kapunahelewong, thanks, in the new version of
zone.js
, we removed thezone-patch-canvas
from thezone.js
bundle, which is a breaking change, I didnāt realize it, we may need to put it back or addimport 'zone.js/dist/zone-patch-canvas'
insrc/polyfills.ts
.