Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(HarnessLoader): Unit tests fail when the harness loader is created in beforeEach #21632

Closed
TrevorKarjanis opened this issue Jan 19, 2021 · 3 comments
Labels
needs triage This issue needs to be triaged by the team

Comments

@TrevorKarjanis
Copy link
Contributor

Reproduction

The unit tests fail when the harness loader is created in an async beforeEach and the TS target is ES2018.
StackBlitz Demo

There are three solutions to this problem.

  1. Move the call to TestbedHarnessEnvironment.loader to the it function (demo).
  2. Use waitForAsync in the beforeEach instead of an async function (demo).
  3. Change the target to ES2016 (demo).

Steps to reproduce:

  1. Create a unit test describe block that includes the harness loader.
  2. Assign the harness loader in the beforeEach function.
  3. Get a harness with await loader.getHander in an async it function.

Expected Behavior

I'd expect the test to pass, because it is setup as described in component harness documentation and ES2018 is the generated default target.

Actual Behavior

TestbedHarnessEnvironment.loader returns undefined in the beforeEach, and the test fails with the following.

Error: Expected to be running in 'ProxyZone', but it was not found.
    at Function.ProxyZoneSpec.assertPresent (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/zone.js@0.11.3/dist/proxy.js:39:23)
    at Function.TaskStateZoneInterceptor.setup (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/@angular/cdk@11.0.4/bundles/cdk-testing-testbed.umd.js:354:42)
    at new TestbedHarnessEnvironment (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/@angular/cdk@11.0.4/bundles/cdk-testing-testbed.umd.js:1167:57)
    at Function.TestbedHarnessEnvironment.loader (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/@angular/cdk@11.0.4/bundles/cdk-testing-testbed.umd.js:1177:20)
    at UserContext.eval (https://harness-issue-hsdvet.stackblitz.io/~/src/app/button-harness-example.spec.ts:21:54)
TypeError: Cannot read property 'getHarness' of undefined
    at UserContext.eval (https://harness-issue-hsdvet.stackblitz.io/~/src/app/button-harness-example.spec.ts:24:37)
    at ZoneDelegate.invoke (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/zone.js@0.11.3/dist/zone.js:395:30)
    at ProxyZoneSpec.onInvoke (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/zone.js@0.11.3/dist/proxy.js:125:43)
    at ZoneDelegate.invoke (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/zone.js@0.11.3/dist/zone.js:394:56)
    at Zone.run (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/zone.js@0.11.3/dist/zone.js:155:47)
    at runInTestZone (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/zone.js@0.11.3/dist/jasmine-patch.js:203:38)
    at UserContext.eval (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/zone.js@0.11.3/dist/jasmine-patch.js:218:24)
    at <Jasmine>

Environment

  • Angular: 11.0.9
  • CDK/Material: 11.0.4
  • Browser(s): Chrome 87.0.4280.141
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS 11.1
@TrevorKarjanis TrevorKarjanis added the needs triage This issue needs to be triaged by the team label Jan 19, 2021
@jelbourn
Copy link
Member

Angular does not actually work with any ES2017 or later output. This is because zone.js cannot patch the native async and await syntax. You can follow the canonical issue for this here: angular/angular#31730. Resolving this is on Angular's roadmap.

@TrevorKarjanis
Copy link
Contributor Author

@jelbourn This might not be the place, but I'd like to selfishly leave a quick piece of feedback. Supporting async/await in testing is awesome! However, I would have expected support for ES next with an option for async/await from your roadmap rather than a blanket drop in support for the whole standard. I don't even use async/await in my application code, because it doesn't support the component lifecycle. That is critical given the types of applications I build, and I find the advantages of CD and RxJS outweigh async/await. I hope the framework continues to progress beyond the standards in those respects after Zone becomes optional. I've been targeting ES2018 for some time, lol.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue needs to be triaged by the team
Projects
None yet
Development

No branches or pull requests

2 participants