Kendo-angular: [Bug] Testing: TypeError: getComputedStyle(...).getPropertyValue is not a function

Created on 1 May 2018  路  6Comments  路  Source: telerik/kendo-angular

I'm submitting a...

  • Bug report

Current behavior

I'm using Jest to run our tests and we're seeing an error when the InputsModule is included for testing. Here's the error:

 TypeError: getComputedStyle(...).getPropertyValue is not a function

      80 |         fixture = TestBed.createComponent(SchemaFieldPropertiesEditorComponent);
      81 |         component = fixture.componentInstance;
    > 82 |         fixture.detectChanges();
      83 |     });
      84 |
      85 |     it("should create", () => {

and a bit of the stack trace:

at computedProp (node_modules/@progress/kendo-angular-resize-sensor/dist/npm/resize-sensor.component.js:12:41)
      at ResizeSensorComponent.Object.<anonymous>.ResizeSensorComponent.ngAfterViewChecked (node_modules/@progress/kendo-angular-resize-sensor/dist/npm/resize-sensor.component.js:69:13)
      at callProviderLifecycles (node_modules/packages/core/esm5/src/view/provider.js:597:2)
      at callElementProvidersLifecycles (node_modules/packages/core/esm5/src/view/provider.js:561:12)
      at callLifecycleHooksChildrenFirst (node_modules/packages/core/esm5/src/view/provider.js:544:2)

Here's the testbed we're using:

 TestBed.configureTestingModule({
                declarations: [
                    SchemaFieldPropertiesEditorComponent,
                    NmSwitchComponent
                ],
                imports: [
                    FormsModule,
                    BrowserModule,
                    BrowserAnimationsModule,
                    MatDialogModule,
                    RouterTestingModule,
                    MatMenuModule,
                    ReactiveFormsModule,
                    ConfirmationDialogsModule,
                    InputsModule
                ],

System:

  • TypeScript version: 2.4
  • Node version: 9
  • Platform: Mac
Question

Most helpful comment

The error can be worked around by mocking getPropertyValue in your setup file:

Object.defineProperty(window, 'getComputedStyle', {
    value: () => ({
        getPropertyValue: (prop) => {
            return '';
        }
    })
});

We may add feature detection if this is a common problem in customers tests. For now, we prefer to keep the code free of JSDOM-specific workarounds.

All 6 comments

Just a quick update, if I remove fixture.detectChanges(); from the test, it passes.

The error can be worked around by mocking getPropertyValue in your setup file:

Object.defineProperty(window, 'getComputedStyle', {
    value: () => ({
        getPropertyValue: (prop) => {
            return '';
        }
    })
});

We may add feature detection if this is a common problem in customers tests. For now, we prefer to keep the code free of JSDOM-specific workarounds.

@tsvetomir thank you! I added it to setupJest.ts and all is working. I Googled for days on this one - hopefully someone else will find this if they need it.

Thank you @tsvetomir! This just made it really easy!

AFAICT, the mock isn't even necessary anymore.

@brandonpittman thanks for pointing this out. The default JSDOM implementation seems to work fine in the current version.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Neaco picture Neaco  路  3Comments

ChrisProlls picture ChrisProlls  路  3Comments

ilianiv picture ilianiv  路  3Comments

tsvetomir picture tsvetomir  路  3Comments

ganySA picture ganySA  路  3Comments