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(ButtonToggle, RadioButton, Tabs): v13 Unit tests using Jest are failing - "ReferenceError: Cannot access 'MatButtonToggle' before initialization" #23907

Closed
1 task done
michaelfaith opened this issue Nov 5, 2021 · 4 comments · Fixed by #23951
Assignees
Labels
area: build & ci Related the build and CI infrastructure of the project P2 The issue is important to a large percentage of users, with a workaround

Comments

@michaelfaith
Copy link

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

12.2.13

Description

We're using Jest for unit testing, with the jest-preset-angular configuration/setup. They've recently updated for v13 support. The tests are running fine, except for components that have Material modules imported. We're seeing this for each:

Test suite failed to run

    ReferenceError: Cannot access 'MatButtonToggle' before initialization

       6 |
       7 | import { ComponentFixture, TestBed } from '@angular/core/testing';
    >  8 | import { MatButtonToggleModule } from '@angular/material/button-toggle';
         | ^
       9 | import { MatIconModule } from '@angular/material/icon';
      10 |
      11 | import { ButtonToggleDemoComponent } from './button-toggle-demo.component';

      at Object.<anonymous> (../../node_modules/@angular/node_modules/@angular/material/fesm2015/button-toggle.mjs:254:63)
      at Object.<anonymous> (src/app/component-demos/button-toggle-demo/button-toggle-demo.component.spec.ts:8:1)

Looking at the failures, it doesn't appear to be all components. The only ones that are causing failures for us are:

  • MatRadioModule
  • MatTabsModule
  • MatButtonToggleModule

Though, it is likely failing on the first errors, so there could be more. But many are definitely passing, so it's not all of them. So far it's just these three that consistently fail.

Reproduction

Simply importing the module import { MatButtonToggleModule } from '@angular/material/button-toggle'; in a Jest unit test, is causing the test to fail. It doesn't even run the tests for that spec, when present.

Expected Behavior

Should import modules successfully.

Actual Behavior

Test suite failed to run

    ReferenceError: Cannot access 'MatButtonToggle' before initialization

       6 |
       7 | import { ComponentFixture, TestBed } from '@angular/core/testing';
    >  8 | import { MatButtonToggleModule } from '@angular/material/button-toggle';
         | ^
       9 | import { MatIconModule } from '@angular/material/icon';
      10 |
      11 | import { ButtonToggleDemoComponent } from './button-toggle-demo.component';

      at Object.<anonymous> (../../node_modules/@angular/node_modules/@angular/material/fesm2015/button-toggle.mjs:254:63)
      at Object.<anonymous> (src/app/component-demos/button-toggle-demo/button-toggle-demo.component.spec.ts:8:1)

Environment

  • Angular: 13.0.0
  • CDK/Material: 13.0.0
  • Browser(s): JSDOM
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10
@michaelfaith michaelfaith added the needs triage This issue needs to be triaged by the team label Nov 5, 2021
@michaelfaith michaelfaith changed the title bug(ButtonToggle, RadioButton, Tabs): Unit tests using Jest are failing - "ReferenceError: Cannot access 'MatButtonToggle' before initialization" bug(ButtonToggle, RadioButton, Tabs): v13 Unit tests using Jest are failing - "ReferenceError: Cannot access 'MatButtonToggle' before initialization" Nov 5, 2021
@devversion devversion self-assigned this Nov 5, 2021
@devversion devversion added area: build & ci Related the build and CI infrastructure of the project P2 The issue is important to a large percentage of users, with a workaround and removed needs triage This issue needs to be triaged by the team labels Nov 5, 2021
@michaelfaith
Copy link
Author

michaelfaith commented Nov 5, 2021

According to @JoostK (thymikee/jest-preset-angular#1090 (comment)) this is being worked on by @petebacondarwin

@devversion
Copy link
Member

devversion commented Nov 5, 2021

@michaelfaith Yeah, this is related to the Angular partial compilation emit not properly dealing with forwardRef and our APF v13 package output therefore emitting invalid Angular declarations for JIT. Once this is fixed upstream, we'll republish a version, and we'll have better testing for ensuring JIT linker-processing works. See #23882

@michaelfaith
Copy link
Author

@devversion Excellent! Thanks for the info. Appreciate the quick response.

petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Nov 8, 2021
…ard references

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Nov 8, 2021
…ard references

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Nov 8, 2021
…ard references

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Nov 8, 2021
…ard references

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Nov 9, 2021
…ard references

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Nov 9, 2021
…ard references

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Nov 10, 2021
…ard references

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Nov 10, 2021
…ard references

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907
atscott pushed a commit to angular/angular that referenced this issue Nov 10, 2021
…ard references (#44113)

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907

PR Close #44113
atscott pushed a commit to angular/angular that referenced this issue Nov 10, 2021
…ard references (#44113)

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907

PR Close #44113
devversion added a commit to devversion/material2 that referenced this issue Nov 11, 2021
…lation output

We updated to Angular v13.0.1 which fixes the partial compilation output
for `forwardRef` usages in queries. The fixed partial compilation output
will ensure that Angular CDK/Material works with JIT linking at runtime,
as done in e.g. Jest.

Fix upstream: angular/angular#44113.

We will add some testing for the JIT linker to the `angular/components`
repository with: angular#23882. That
should help ensuring JIT linking does not regress.

Fixes angular#23907.
devversion added a commit to devversion/material2 that referenced this issue Nov 11, 2021
…lation output

Updates to Angular v13.0.1 which fixes the partial compilation output
for `forwardRef` usages in queries. The fixed partial compilation output
will ensure that Angular CDK/Material works with JIT linking at runtime,
as done in e.g. Jest.

Fix upstream: angular/angular#44113.

We will add some testing for the JIT linker to the `angular/components`
repository with: angular#23882. That
should help ensuring JIT linking does not regress.

Fixes angular#23907.
amysorto pushed a commit that referenced this issue Nov 11, 2021
…lation output (#23951)

Updates to Angular v13.0.1 which fixes the partial compilation output
for `forwardRef` usages in queries. The fixed partial compilation output
will ensure that Angular CDK/Material works with JIT linking at runtime,
as done in e.g. Jest.

Fix upstream: angular/angular#44113.

We will add some testing for the JIT linker to the `angular/components`
repository with: #23882. That
should help ensuring JIT linking does not regress.

Fixes #23907.
amysorto pushed a commit that referenced this issue Nov 11, 2021
…lation output (#23951)

Updates to Angular v13.0.1 which fixes the partial compilation output
for `forwardRef` usages in queries. The fixed partial compilation output
will ensure that Angular CDK/Material works with JIT linking at runtime,
as done in e.g. Jest.

Fix upstream: angular/angular#44113.

We will add some testing for the JIT linker to the `angular/components`
repository with: #23882. That
should help ensuring JIT linking does not regress.

Fixes #23907.

(cherry picked from commit 8cb0f12)
AndrewKushnir pushed a commit to angular/angular that referenced this issue Nov 16, 2021
…ard references (#44124)

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907

PR Close #44124
@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 Dec 12, 2021
forsti0506 pushed a commit to forsti0506/components that referenced this issue Apr 3, 2022
…lation output (angular#23951)

Updates to Angular v13.0.1 which fixes the partial compilation output
for `forwardRef` usages in queries. The fixed partial compilation output
will ensure that Angular CDK/Material works with JIT linking at runtime,
as done in e.g. Jest.

Fix upstream: angular/angular#44113.

We will add some testing for the JIT linker to the `angular/components`
repository with: angular#23882. That
should help ensuring JIT linking does not regress.

Fixes angular#23907.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: build & ci Related the build and CI infrastructure of the project P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
2 participants