question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 run yarn 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:

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
JiaLiPassioncommented, Jun 10, 2019

@frederikprijck, sure I will check it.

1reaction
JiaLiPassioncommented, Jun 10, 2019

@kapunahelewong, thanks, in the new version of zone.js, we removed the zone-patch-canvas from the zone.js bundle, which is a breaking change, I didn’t realize it, we may need to put it back or add import 'zone.js/dist/zone-patch-canvas' in src/polyfills.ts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing - Angular
The testing documentation offers tips and techniques for unit and integration testing Angular applications through a sample application created with theĀ ...
Read more >
Avoiding relative paths in Angular CLI - Stack Overflow
Per this comment, you can add your application source via paths in tsconfig.json : { "compilerOptions": { ..., "baseUrl": ".", "paths": { ...,...
Read more >
Angular App Shell - Boost Application Startup Performance
Table Of Contents Ā· Step 1 - Scaffolding an Angular PWA Application with the Angular CLI Ā· Step 2 - Checking the index....
Read more >
Wallaby - Immediate JavaScript test feedback in your IDE as ...
Wallaby runs your JavaScript and TypeScript tests immediately as you type in VS Code, WebStorm and other editors, highlighting results next to your...
Read more >
AIO Tests (All-In-One Test Management for Jira)
Jira-native QA app for end-to-end Test Management. Test Cases, Cycles, Reports, Automation & more. Feature packed yet affordable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found