Nx: Unit tests run in non-ivy mode

Created on 28 Mar 2020  路  3Comments  路  Source: nrwl/nx

Expected Behavior

Jest unit tests run in ivy mode

Current Behavior

Unit tests run in non-ivy mode

Steps to Reproduce

  1. add this to component's OnInit
import { 傻ivyEnabled as ivyEnabled } from '@angular/core';

  public ngOnInit(): void {
    console.log('> ivyEnabled', ivyEnabled);
  }
  1. run component's test and see false in console

It returns true in browser.

Context

  @nrwl/angular : 9.1.4
  @nrwl/cli : 9.1.4
  @nrwl/cypress : 9.1.4
  @nrwl/eslint-plugin-nx : Not Found
  @nrwl/express : Not Found
  @nrwl/jest : 9.1.4
  @nrwl/linter : Not Found
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 9.1.4
  @nrwl/web : Not Found
  @nrwl/workspace : 9.1.4
  typescript : 3.7.5

Other

Running component's tests in non-ivy mode many stuff that are built with ivy support will not work and we have contradictions how component behave in browser and in tests.
E.x. regular task - unsubscribing on destroy via custom operator/decorator, like this library https://github.com/ngneat/until-destroy/. Currently it fails in tests on start

    TypeError: Cannot read property 'onDestroy' of undefined

because is looking for ivy-related properties on component for proper work and has not found them.

angular feature

Most helpful comment

@brandonroberts How is this solved? The default behavior seems broken, the _workaround_ isn't a fix. 馃槙 All unit tests are running in non-ivy mode with Jest.

All 3 comments

Please take a look here: Cannot test @Injectable() services with Jest

Do you have this postinstall command:

ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points

if so try changing it to just ngcc and try again.

Closing as resolved

@brandonroberts How is this solved? The default behavior seems broken, the _workaround_ isn't a fix. 馃槙 All unit tests are running in non-ivy mode with Jest.

Was this page helpful?
0 / 5 - 0 ratings