Skip to content

tests failing on angular 9 after running ngcc with @angular/localize #347

@pkaufi

Description

@pkaufi

Describe the Bug

After running ngcc as proposed in the angular update guide (https://update.angular.io/#8.2:9.0), tests are failing with the error message

It looks like your application or one of its dependencies is using i18n.
Angular 9 introduced a global `$localize()` function that needs to be loaded.
Please run `ng add @angular/localize` from the Angular CLI.
(For non-CLI projects, add `import '@angular/localize/init';` to your `polyfills.ts` file.
For server-side rendering applications add the import to your `main.server.ts` file.)

I added a small reproduction below (updated and adapted the example app in this repository), where I installed @angular/localized with the help of the cli (ng add @angular/localized). It then added an import to the polyfills.ts files automatically (polyfills.ts).
After I investigated a bit, I found out, that polyfills.ts is not picked up during the test run.
When you add either import './polyfills'; or import '@angular/localize/init'; to setupJest.ts, the tests run successfully. But isn't that what we have the tsconfig's for? In tsconfig.spec.json for example, you can see that we have

"files": [
    "src/polyfills.ts"
  ]

What seems strange to me is and what I don't understand is, that before you run ngcc, the tests run successfully, even though polyfills.ts is not picked up. However, I also don't know exactly what ngcc is doing.

Minimal Reproduction

https://github.com/pkaufi/ngcc-i18n-jest/tree/jest-preset-angular

Expected Behavior

Tests should run successfully after running ngcc

Environment

see reproduction repository

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not An IssueNot jest-preset-angular issueivyIvy compatible

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions