Skip to content

bug(cdk/a11y): Observable in HighContrastModeDetector constructor is undefined #25563

@cjlawson02

Description

@cjlawson02

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

14.0.1

Description

Caused by #25088

This line fails during Karma testing because the observe call before it returns undefined

Stack trace:

    TypeError: Cannot read properties of undefined (reading 'subscribe')
        at new HighContrastModeDetector (node_modules/@angular/cdk/fesm2020/a11y.mjs:2348:40)
        at Object.factory (node_modules/@angular/cdk/fesm2020/a11y.mjs:2406:1)
        at R3Injector.hydrate (node_modules/@angular/core/fesm2020/core.mjs:9258:35)
        at R3Injector.get (node_modules/@angular/core/fesm2020/core.mjs:9146:33)
        at injectInjectorOnly (node_modules/@angular/core/fesm2020/core.mjs:4778:33)
        at Module.ɵɵinject (node_modules/@angular/core/fesm2020/core.mjs:4782:12)
        at Object.useFactory (node_modules/@angular/material/fesm2020/core.mjs:105:1)
        at Object.factory (node_modules/@angular/core/fesm2020/core.mjs:9345:38)
        at R3Injector.hydrate (node_modules/@angular/core/fesm2020/core.mjs:9258:35)
        at R3Injector.get (node_modules/@angular/core/fesm2020/core.mjs:9146:33)

Reproduction

I'm unsure how to completely reproduce, and I'm unable to share the code due to NDA.

Expected Behavior

HighContrastModeDetector successfully constructs

Actual Behavior

Constructor fails on only 2 of my components at the line linked above due to the expected Observable being undefined.

Environment

  • Angular: Fails on 14.0.2, 14.1.3, and 14.2.0-rc.0
  • CDK/Material: CDK
  • Browser(s): Chrome Headless Karma/Jasmine
  • Operating System (e.g. Windows, macOS, Ubuntu): Amazon Linux 2

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