From 695c73022c4011cca477b8d6d62c174a8c01a9ec Mon Sep 17 00:00:00 2001 From: Ahn <27772165+ahnpnl@users.noreply.github.com> Date: Sun, 25 Sep 2022 16:06:49 +0200 Subject: [PATCH] feat(config): remove hardcoded logic setting `target` to `ES2015` (#1788) --- README.md | 4 ++++ e2e/async/jest.config.js | 5 ++--- src/config/ng-jest-config.spec.ts | 15 --------------- src/config/ng-jest-config.ts | 6 ------ website/docs/getting-started/installation.md | 6 ++++++ .../version-12.0/getting-started/installation.md | 6 ++++++ 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index eef10ea411..e569c52af2 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,10 @@ Adjust your `tsconfig.spec.json` to be: } ``` +**IMPORTANT** + +Angular doesn't support native `async/await` in testing with `target` higher than `ES2016`, see https://github.com/angular/components/issues/21632#issuecomment-764975917 + ## Migration from Angular < 13 Check out our [Migration from Angular < 13 guidance](https://thymikee.github.io/jest-preset-angular/docs/guides/angular-13+) diff --git a/e2e/async/jest.config.js b/e2e/async/jest.config.js index d8e6b0385b..0880455d20 100644 --- a/e2e/async/jest.config.js +++ b/e2e/async/jest.config.js @@ -2,11 +2,10 @@ module.exports = { globals: { 'ts-jest': { tsconfig: { - /** - * Set at ES2018 to test Angular doesn't work with ES2017+ + /** Angular doesn't work with ES2017+ * see https://github.com/angular/components/issues/21632#issuecomment-764975917 */ - target: 'ES2018', + target: 'ES2016', }, }, }, diff --git a/src/config/ng-jest-config.spec.ts b/src/config/ng-jest-config.spec.ts index 92fc0127e2..d088e91f82 100644 --- a/src/config/ng-jest-config.spec.ts +++ b/src/config/ng-jest-config.spec.ts @@ -15,19 +15,4 @@ describe('NgJestConfig', () => { expect(compilerOptions.allowJs).toBe(true); expect(compilerOptions.target).toBe(ScriptTarget.ES2015); }); - - test('should set typescript target to ES2015 if user is using target higher than ES2016', () => { - expect( - new NgJestConfig({ - globals: { - 'ts-jest': { - tsconfig: { - target: 'ES2017', - }, - }, - }, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any).parsedTsConfig.options.target, - ).toBe(ScriptTarget.ES2015); - }); }); diff --git a/src/config/ng-jest-config.ts b/src/config/ng-jest-config.ts index 32c6e6364c..057553fd91 100644 --- a/src/config/ng-jest-config.ts +++ b/src/config/ng-jest-config.ts @@ -33,12 +33,6 @@ export class NgJestConfig extends ConfigSet { result.options.enableResourceInlining = false; // Since we define preset default also transform `js` so we need to set `allowJs` true result.options.allowJs = true; - const ts = this.compilerModule; - const scriptTarget = result.options.target ?? ts.ScriptTarget?.ES2015; - if (scriptTarget > ts.ScriptTarget?.ES2016) { - // See https://github.com/angular/components/issues/21632#issuecomment-764975917 - result.options.target = ts.ScriptTarget?.ES2015; - } return result; } diff --git a/website/docs/getting-started/installation.md b/website/docs/getting-started/installation.md index 097dcb594e..4423cd6a12 100644 --- a/website/docs/getting-started/installation.md +++ b/website/docs/getting-started/installation.md @@ -75,6 +75,12 @@ Adjust your `tsconfig.spec.json` to be: } ``` +:::important + +Angular doesn't support native `async/await` in testing with `target` higher than `ES2016`, see https://github.com/angular/components/issues/21632#issuecomment-764975917 + +::: + ### Customizing #### Global mocks diff --git a/website/versioned_docs/version-12.0/getting-started/installation.md b/website/versioned_docs/version-12.0/getting-started/installation.md index 097dcb594e..4423cd6a12 100644 --- a/website/versioned_docs/version-12.0/getting-started/installation.md +++ b/website/versioned_docs/version-12.0/getting-started/installation.md @@ -75,6 +75,12 @@ Adjust your `tsconfig.spec.json` to be: } ``` +:::important + +Angular doesn't support native `async/await` in testing with `target` higher than `ES2016`, see https://github.com/angular/components/issues/21632#issuecomment-764975917 + +::: + ### Customizing #### Global mocks