jest-preset-angular: Missing dependency, and other failures with 9.0.0-next.2

🐛 Bug Report

While testing Ivy support using 9.0.0-next.2, I ran into some significant issues. They are as follows:

Background: We have a medium-sized project with a few hundred tests using jest-preset-angular for some time. It does not have many external dependencies by most Angular project standards.

  1. After first upgrading to jest-preset-angular@9.0.0-next.2, I received this error for every test:
 FAIL  libs/ui-components/dialog/src/dialog-close.directive.spec.ts
  ● Test suite failed to run
    
	Cannot find module '@ngtools/webpack/src/diagnostics'
    Require stack:
    - C:\src\ease\WebUi\node_modules\jest-preset-angular\build\compiler\ng-jest-compiler.js
    - C:\src\ease\WebUi\node_modules\jest-preset-angular\build\index.js
    - C:\src\ease\WebUi\node_modules\@jest\transform\build\ScriptTransformer.js
    - C:\src\ease\WebUi\node_modules\@jest\transform\build\index.js
    - C:\src\ease\WebUi\node_modules\jest-runtime\build\index.js
    - C:\src\ease\WebUi\node_modules\jest-runner\build\testWorker.js
    - C:\src\ease\WebUi\node_modules\jest-worker\build\workers\processChild.js

      at Object.<anonymous> (node_modules/jest-preset-angular/build/compiler/ng-jest-compiler.js:6:21)

To fix this, I tried:

> yarn add -D @ngtools/webpack

...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ @ngtools/webpack@10.2.0
info All dependencies
└─ @ngtools/webpack@10.2.0	 

This may be the cause of the following problems.

  1. Now, while running tests, I experienced a “hang” for 8+ minutes before any tests were run. It may have been longer - I tried attaching a debugger but wasn’t able to. After this, the starting “hang” seems shorter - a minute or two.

Eventually some tests were run, but I’m seeing a large number of odd compile + runtime errors. A single digit number of tests passed successfully.

The main compile error I’m seeing is:

    libs/ui-components/form/src/text-field/text-field.component.ts:50:43 - error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.

    50     return this._input?.disabled ?? super.disabled;

Runtime errors include a lot of these (intermixed):

1:

Failed: "Zone is needed for the waitForAsync() test helper but could not be found. Please make sure that your environment includes zone.js/dist/zone.js"

      17 |   let intersectionObserverService: IntersectionObserverServiceMock;
      18 | 
    > 19 |   beforeEach(waitForAsync(() => {
         |   ^
      20 |     configureTestBed(TestDefaultComponent);
      21 | 
      22 |     fixture = createTestComponent(TestDefaultComponent);

      at Env.beforeEach (node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:46:24)

2:


    TypeError: Cannot read property 'debugElement' of undefined

      181 | 
      182 |   it('should unsubscribe from intersection observer', () => {
    > 183 |     const button = fixture.debugElement.query(By.directive(VisibilityTrackingDirective));
          |                            ^
      184 |     expect(button).toBeDefined();
      185 | 
      186 |     showElement(button, 1000, 0.1, intersectionObserverService);

To Reproduce

Let me know if you’d like me to create a public repro with a few tests exhibiting these problems. I’m happy to, but wanted to start with a report.

envinfo

System:
    OS: Windows 10

Npm packages:
   jest@26.6.3
   jest-preset-angular@9.0.0-next.2
   typescript@4.0.5

Related to #409

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (12 by maintainers)

Commits related to this issue

Most upvoted comments

This issue https://github.com/microsoft/TypeScript/issues/15842 also says that ES5 doesn’t work while ES6 does

    TypeError: Cannot read property 'getComponentFromError' of null

      at TestBedViewEngine.Object.<anonymous>.TestBedViewEngine._initIfNeeded (../packages/core/testing/src/test_bed.ts:391:46)
      at TestBedViewEngine.Object.<anonymous>.TestBedViewEngine.inject (../packages/core/testing/src/test_bed.ts:480:10)
      at Function.Object.<anonymous>.TestBedViewEngine.inject (../packages/core/testing/src/test_bed.ts:227:36)
      at Object.<anonymous> (libs/ui-tracking/src/tracking/tracking.service.spec.ts:165:25)

This indicates to me that we may be getting the wrong version of the TestBed . As far as I can tell all of our tsconfig files inherit from our base tsconfig, which has "enableIvy": true. Any suggestions for switching the TestBed to use Ivy?

Currently we haven’t integrated automatical ngcc in the compilation process yet. Therefore you need to make sure that ngcc is run before running tests. The error looks to me that ngcc hasn’t been run yet.