From 528feb56f3e77399ab2f596500e4f474075e74a6 Mon Sep 17 00:00:00 2001 From: Ahn Date: Sat, 12 Dec 2020 02:13:41 +0100 Subject: [PATCH] test(e2e): add entry component example with Ivy --- README.md | 2 -- e2e/test-app-v10-zone-v11/package.json | 3 +-- e2e/test-app-v10/package.json | 5 ++-- .../dynamic-button.component.ts | 15 ++++++++++++ .../dynamic-host.component.spec.ts | 19 +++++++++++++++ .../dynamic-host.component.ts | 12 ++++++++++ .../dynamic-component/dynamic-host.module.ts | 10 ++++++++ e2e/test-app-v9/package.json | 5 ++-- .../src/app/on-push/on-push.component.spec.ts | 2 +- package.json | 7 +++--- yarn.lock | 24 +++++++++---------- 11 files changed, 78 insertions(+), 26 deletions(-) create mode 100644 e2e/test-app-v10/src/app/dynamic-component/dynamic-button.component.ts create mode 100644 e2e/test-app-v10/src/app/dynamic-component/dynamic-host.component.spec.ts create mode 100644 e2e/test-app-v10/src/app/dynamic-component/dynamic-host.component.ts create mode 100644 e2e/test-app-v10/src/app/dynamic-component/dynamic-host.module.ts diff --git a/README.md b/README.md index 538864ffe3..ba5fce1992 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ This is a part of the article: [Testing Angular faster with Jest](https://www.xfive.co/blog/testing-angular-faster-jest/). -_Note: This preset does not support AngularJS (1.x). If you want to set up Jest with AngularJS, please see [this blog post](https://medium.com/aya-experience/testing-an-angularjs-app-with-jest-3029a613251)._ - ## Table of Contents diff --git a/e2e/test-app-v10-zone-v11/package.json b/e2e/test-app-v10-zone-v11/package.json index e680a8f6c8..9a3c621c45 100644 --- a/e2e/test-app-v10-zone-v11/package.json +++ b/e2e/test-app-v10-zone-v11/package.json @@ -6,8 +6,7 @@ "start": "ng serve", "build": "ng build", "test": "jest --no-cache", - "lint": "ng lint", - "postinstall": "ngcc" + "lint": "ng lint" }, "private": true, "dependencies": { diff --git a/e2e/test-app-v10/package.json b/e2e/test-app-v10/package.json index 16d227b220..1b7b634375 100644 --- a/e2e/test-app-v10/package.json +++ b/e2e/test-app-v10/package.json @@ -6,8 +6,7 @@ "start": "ng serve", "build": "ng build", "test": "jest --no-cache", - "lint": "ng lint", - "postinstall": "ngcc" + "lint": "ng lint" }, "private": true, "dependencies": { @@ -36,4 +35,4 @@ "tslint": "~6.1.3", "typescript": "~4.0.5" } -} \ No newline at end of file +} diff --git a/e2e/test-app-v10/src/app/dynamic-component/dynamic-button.component.ts b/e2e/test-app-v10/src/app/dynamic-component/dynamic-button.component.ts new file mode 100644 index 0000000000..879c260875 --- /dev/null +++ b/e2e/test-app-v10/src/app/dynamic-component/dynamic-button.component.ts @@ -0,0 +1,15 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-dynamic-button', + template: ` + + `, +}) +export class DynamicButtonComponent { + onClick() { + console.log('Click!'); + } +} diff --git a/e2e/test-app-v10/src/app/dynamic-component/dynamic-host.component.spec.ts b/e2e/test-app-v10/src/app/dynamic-component/dynamic-host.component.spec.ts new file mode 100644 index 0000000000..01d7322cd2 --- /dev/null +++ b/e2e/test-app-v10/src/app/dynamic-component/dynamic-host.component.spec.ts @@ -0,0 +1,19 @@ +import { TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DynamicHostComponent } from './dynamic-host.component'; +import { DynamicHostModule } from './dynamic-host.module'; + +describe('Dynamic components', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ DynamicHostModule ], + }); + }); + + it('dynamically renders a button', async () => { + const fixture = TestBed.createComponent(DynamicHostComponent); + fixture.detectChanges(); + const button = fixture.debugElement.query(By.css('button')).nativeElement as HTMLButtonElement; + expect(button.textContent).toContain('Hello'); + }); +}); diff --git a/e2e/test-app-v10/src/app/dynamic-component/dynamic-host.component.ts b/e2e/test-app-v10/src/app/dynamic-component/dynamic-host.component.ts new file mode 100644 index 0000000000..5107041d0c --- /dev/null +++ b/e2e/test-app-v10/src/app/dynamic-component/dynamic-host.component.ts @@ -0,0 +1,12 @@ +import { Component } from '@angular/core'; +import { DynamicButtonComponent } from './dynamic-button.component'; + +@Component({ + selector: 'app-dynamic-host', + template: ` + + `, +}) +export class DynamicHostComponent { + dynamicComponentType = DynamicButtonComponent; +} diff --git a/e2e/test-app-v10/src/app/dynamic-component/dynamic-host.module.ts b/e2e/test-app-v10/src/app/dynamic-component/dynamic-host.module.ts new file mode 100644 index 0000000000..adda9e76f9 --- /dev/null +++ b/e2e/test-app-v10/src/app/dynamic-component/dynamic-host.module.ts @@ -0,0 +1,10 @@ +import { CommonModule } from '@angular/common'; +import { NgModule } from '@angular/core'; +import { DynamicHostComponent } from './dynamic-host.component'; + +@NgModule({ + declarations: [DynamicHostComponent], + exports: [DynamicHostComponent], + imports: [CommonModule], +}) +export class DynamicHostModule {} diff --git a/e2e/test-app-v9/package.json b/e2e/test-app-v9/package.json index 0f9f7af43f..0d02db6b98 100644 --- a/e2e/test-app-v9/package.json +++ b/e2e/test-app-v9/package.json @@ -6,8 +6,7 @@ "start": "ng serve", "build": "ng build", "test": "jest --no-cache", - "lint": "ng lint", - "postinstall": "ngcc" + "lint": "ng lint" }, "private": true, "dependencies": { @@ -34,4 +33,4 @@ "ts-node": "^9.0.0", "typescript": "~3.8.3" } -} \ No newline at end of file +} diff --git a/e2e/test-app-v9/src/app/on-push/on-push.component.spec.ts b/e2e/test-app-v9/src/app/on-push/on-push.component.spec.ts index e569a8f184..caa4299f7c 100644 --- a/e2e/test-app-v9/src/app/on-push/on-push.component.spec.ts +++ b/e2e/test-app-v9/src/app/on-push/on-push.component.spec.ts @@ -1,4 +1,4 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { async, ComponentFixture } from '@angular/core/testing'; import { ChangeDetectionStrategy } from '@angular/core'; import { ConfigureFn, configureTests } from '@lib/testing'; diff --git a/package.json b/package.json index 0336459f6f..816bc45576 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "ts-jest": "^26.2.0" }, "peerDependencies": { + "@angular-devkit/build-angular": ">=0.901.12", "@angular/core": ">=9.0.0", "@angular/platform-browser-dynamic": ">=9.0.0", "jest": "^26.0.0" @@ -42,9 +43,9 @@ "webpack": "^4.0.0" }, "devDependencies": { - "@angular/compiler": "^10.1.4", - "@angular/compiler-cli": "^10.1.4", - "@angular/core": "^11.0.0", + "@angular/compiler": "^10.2.3", + "@angular/compiler-cli": "^10.2.3", + "@angular/core": "^10.2.3", "@commitlint/cli": "11.x", "@commitlint/config-angular": "11.x", "@jest/transform": "26.x", diff --git a/yarn.lock b/yarn.lock index 89ed4d0492..dae9b4075d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13,10 +13,10 @@ rxjs "6.6.2" source-map "0.7.3" -"@angular/compiler-cli@^10.1.4": - version "10.1.4" - resolved "https://registry.yarnpkg.com/@angular/compiler-cli/-/compiler-cli-10.1.4.tgz#b5aaa7de6173b83ce3ba066232b8c088f2428642" - integrity sha512-5jRL9TKSGQLlP+C3gdJmSjYv7BfzN69SuYir/o0OtBblqzsGeaA21ClPMXl/HOxjFSjnIyGgjN7Caf7VjeMJww== +"@angular/compiler-cli@^10.2.3": + version "10.2.3" + resolved "https://registry.yarnpkg.com/@angular/compiler-cli/-/compiler-cli-10.2.3.tgz#b43cf9e6ed163645959010c6421fb88819a5943c" + integrity sha512-29RL/lIbHpjoWMUz23cyRcyG50PXqvxlLk0IpyCUWDVtPp6Hc8S/JayxeSwxNST79miDobGaeiGmS0JHuCouVQ== dependencies: canonical-path "1.0.0" chokidar "^3.0.0" @@ -32,17 +32,17 @@ tslib "^2.0.0" yargs "15.3.0" -"@angular/compiler@^10.1.4": - version "10.1.4" - resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-10.1.4.tgz#76268332edb289b282296560e41478a2e323a39c" - integrity sha512-3vkaLE1kfyfkNoU/sf982UBMtB1bvFgBKHdP+YG7qlxVL1nLlQQvzIHKV8YGgtWnK2PMoJMI51In/64M71T0hg== +"@angular/compiler@^10.2.3": + version "10.2.3" + resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-10.2.3.tgz#4f2a42d1b479d323118fe33e1e62594d029ed5f9" + integrity sha512-Bg+QbyvJVlfGQpJCagEMkkqoRi2LMQc8iuu+cVYVqQOETLO0LxmkPpMQ/7pRLTNWl36PoYEB7IjUkp+qng8xKg== dependencies: tslib "^2.0.0" -"@angular/core@^11.0.0": - version "11.0.4" - resolved "https://registry.yarnpkg.com/@angular/core/-/core-11.0.4.tgz#8eebb6a550dc24e4d53f642c8a78a0da2830cd5b" - integrity sha512-860cTMjdCHcvEsHOsTzpg5rThxwVgtnY4yT0SgboWiphrlzX+aNoyN/cCJHxWhmOTRlrl6/+hkeRq95E2BZkKw== +"@angular/core@^10.2.3": + version "10.2.3" + resolved "https://registry.yarnpkg.com/@angular/core/-/core-10.2.3.tgz#89469c537b304532d6aa8dbb2ea4e1e2ed90e7a6" + integrity sha512-mE6nLpul/IJllk0VYrlrP69n0P7JPz+BHYAVobwO5+0EGO65ieTD18DxzfEt4eQgthnM3VQwSZxjW4n9Y1p/dQ== dependencies: tslib "^2.0.0"