Skip to content

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

Closed
@TrevorKarjanis

Description

@TrevorKarjanis

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/[email protected]/dist/proxy.js:39:23)
    at Function.TaskStateZoneInterceptor.setup (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/@angular/[email protected]/bundles/cdk-testing-testbed.umd.js:354:42)
    at new TestbedHarnessEnvironment (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/@angular/[email protected]/bundles/cdk-testing-testbed.umd.js:1167:57)
    at Function.TestbedHarnessEnvironment.loader (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/@angular/[email protected]/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/[email protected]/dist/zone.js:395:30)
    at ProxyZoneSpec.onInvoke (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/[email protected]/dist/proxy.js:125:43)
    at ZoneDelegate.invoke (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/[email protected]/dist/zone.js:394:56)
    at Zone.run (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/[email protected]/dist/zone.js:155:47)
    at runInTestZone (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/[email protected]/dist/jasmine-patch.js:203:38)
    at UserContext.eval (https://harness-issue-hsdvet.stackblitz.io/turbo_modules/[email protected]/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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue needs to be triaged by the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions