From 65175ddf50214b93767d9253fa17983d69a50a2d Mon Sep 17 00:00:00 2001 From: MG Date: Fri, 10 Jul 2020 23:11:18 +0200 Subject: [PATCH] fix: adding NG_VALUE_ACCESSOR for mat components closes #157 --- e2e/a10es2015ivy/src/app/app.component.html | 1 - e2e/a10es2015ivy/src/app/app.component.scss | 0 e2e/a10es2015ivy/src/app/app.component.ts | 3 +- e2e/a10es2015noivy/src/app/app.component.html | 1 - e2e/a10es2015noivy/src/app/app.component.scss | 0 e2e/a10es2015noivy/src/app/app.component.ts | 3 +- e2e/a10es5ivy/src/app/app.component.html | 1 - e2e/a10es5ivy/src/app/app.component.scss | 0 e2e/a10es5ivy/src/app/app.component.ts | 3 +- e2e/a10es5noivy/src/app/app.component.html | 1 - e2e/a10es5noivy/src/app/app.component.scss | 0 e2e/a10es5noivy/src/app/app.component.ts | 3 +- e2e/a5es2015/src/app/app.component.css | 0 e2e/a5es2015/src/app/app.component.html | 1 - e2e/a5es2015/src/app/app.component.ts | 10 +-- e2e/a5es5/src/app/app.component.css | 0 e2e/a5es5/src/app/app.component.html | 1 - e2e/a5es5/src/app/app.component.ts | 10 +-- e2e/a6es2015/src/app/app.component.html | 1 - e2e/a6es2015/src/app/app.component.scss | 0 e2e/a6es2015/src/app/app.component.ts | 3 +- e2e/a6es5/src/app/app.component.html | 1 - e2e/a6es5/src/app/app.component.scss | 0 e2e/a6es5/src/app/app.component.ts | 3 +- e2e/a7es2015/src/app/app.component.html | 1 - e2e/a7es2015/src/app/app.component.scss | 0 e2e/a7es2015/src/app/app.component.ts | 3 +- e2e/a7es5/src/app/app.component.html | 1 - e2e/a7es5/src/app/app.component.scss | 0 e2e/a7es5/src/app/app.component.ts | 3 +- e2e/a8es2015/src/app/app.component.html | 1 - e2e/a8es2015/src/app/app.component.scss | 0 e2e/a8es2015/src/app/app.component.ts | 3 +- e2e/a8es5/src/app/app.component.html | 1 - e2e/a8es5/src/app/app.component.scss | 0 e2e/a8es5/src/app/app.component.ts | 3 +- e2e/a9es2015ivy/package-lock.json | 21 +++++ e2e/a9es2015ivy/package.json | 2 + e2e/a9es2015ivy/src/app/app.component.html | 1 - e2e/a9es2015ivy/src/app/app.component.scss | 0 e2e/a9es2015ivy/src/app/app.component.ts | 3 +- e2e/a9es2015noivy/src/app/app.component.html | 1 - e2e/a9es2015noivy/src/app/app.component.scss | 0 e2e/a9es2015noivy/src/app/app.component.ts | 3 +- e2e/a9es5ivy/src/app/app.component.html | 1 - e2e/a9es5ivy/src/app/app.component.scss | 0 e2e/a9es5ivy/src/app/app.component.ts | 3 +- e2e/a9es5noivy/src/app/app.component.html | 1 - e2e/a9es5noivy/src/app/app.component.scss | 0 e2e/a9es5noivy/src/app/app.component.ts | 3 +- lib/mock-component/mock-component.ts | 26 ++++-- lib/mock-directive/mock-directive.ts | 12 +-- tests/issue-157/components.spec.ts | 85 +++++++++++++++++++ tslint.json | 1 + 54 files changed, 157 insertions(+), 68 deletions(-) delete mode 100644 e2e/a10es2015ivy/src/app/app.component.html delete mode 100644 e2e/a10es2015ivy/src/app/app.component.scss delete mode 100644 e2e/a10es2015noivy/src/app/app.component.html delete mode 100644 e2e/a10es2015noivy/src/app/app.component.scss delete mode 100644 e2e/a10es5ivy/src/app/app.component.html delete mode 100644 e2e/a10es5ivy/src/app/app.component.scss delete mode 100644 e2e/a10es5noivy/src/app/app.component.html delete mode 100644 e2e/a10es5noivy/src/app/app.component.scss delete mode 100644 e2e/a5es2015/src/app/app.component.css delete mode 100644 e2e/a5es2015/src/app/app.component.html delete mode 100644 e2e/a5es5/src/app/app.component.css delete mode 100644 e2e/a5es5/src/app/app.component.html delete mode 100644 e2e/a6es2015/src/app/app.component.html delete mode 100644 e2e/a6es2015/src/app/app.component.scss delete mode 100644 e2e/a6es5/src/app/app.component.html delete mode 100644 e2e/a6es5/src/app/app.component.scss delete mode 100644 e2e/a7es2015/src/app/app.component.html delete mode 100644 e2e/a7es2015/src/app/app.component.scss delete mode 100644 e2e/a7es5/src/app/app.component.html delete mode 100644 e2e/a7es5/src/app/app.component.scss delete mode 100644 e2e/a8es2015/src/app/app.component.html delete mode 100644 e2e/a8es2015/src/app/app.component.scss delete mode 100644 e2e/a8es5/src/app/app.component.html delete mode 100644 e2e/a8es5/src/app/app.component.scss delete mode 100644 e2e/a9es2015ivy/src/app/app.component.html delete mode 100644 e2e/a9es2015ivy/src/app/app.component.scss delete mode 100644 e2e/a9es2015noivy/src/app/app.component.html delete mode 100644 e2e/a9es2015noivy/src/app/app.component.scss delete mode 100644 e2e/a9es5ivy/src/app/app.component.html delete mode 100644 e2e/a9es5ivy/src/app/app.component.scss delete mode 100644 e2e/a9es5noivy/src/app/app.component.html delete mode 100644 e2e/a9es5noivy/src/app/app.component.scss create mode 100644 tests/issue-157/components.spec.ts diff --git a/e2e/a10es2015ivy/src/app/app.component.html b/e2e/a10es2015ivy/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a10es2015ivy/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a10es2015ivy/src/app/app.component.scss b/e2e/a10es2015ivy/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a10es2015ivy/src/app/app.component.ts b/e2e/a10es2015ivy/src/app/app.component.ts index 6cdc4580e9..9b6e0b1392 100644 --- a/e2e/a10es2015ivy/src/app/app.component.ts +++ b/e2e/a10es2015ivy/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a10es2015noivy/src/app/app.component.html b/e2e/a10es2015noivy/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a10es2015noivy/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a10es2015noivy/src/app/app.component.scss b/e2e/a10es2015noivy/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a10es2015noivy/src/app/app.component.ts b/e2e/a10es2015noivy/src/app/app.component.ts index 6cdc4580e9..9b6e0b1392 100644 --- a/e2e/a10es2015noivy/src/app/app.component.ts +++ b/e2e/a10es2015noivy/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a10es5ivy/src/app/app.component.html b/e2e/a10es5ivy/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a10es5ivy/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a10es5ivy/src/app/app.component.scss b/e2e/a10es5ivy/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a10es5ivy/src/app/app.component.ts b/e2e/a10es5ivy/src/app/app.component.ts index 6cdc4580e9..9b6e0b1392 100644 --- a/e2e/a10es5ivy/src/app/app.component.ts +++ b/e2e/a10es5ivy/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a10es5noivy/src/app/app.component.html b/e2e/a10es5noivy/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a10es5noivy/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a10es5noivy/src/app/app.component.scss b/e2e/a10es5noivy/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a10es5noivy/src/app/app.component.ts b/e2e/a10es5noivy/src/app/app.component.ts index 6cdc4580e9..9b6e0b1392 100644 --- a/e2e/a10es5noivy/src/app/app.component.ts +++ b/e2e/a10es5noivy/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a5es2015/src/app/app.component.css b/e2e/a5es2015/src/app/app.component.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a5es2015/src/app/app.component.html b/e2e/a5es2015/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a5es2015/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a5es2015/src/app/app.component.ts b/e2e/a5es2015/src/app/app.component.ts index 5c65edda89..9b6e0b1392 100644 --- a/e2e/a5es2015/src/app/app.component.ts +++ b/e2e/a5es2015/src/app/app.component.ts @@ -1,10 +1,8 @@ -import { Component } from '@angular/core'; +import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.css'], + template: 'ng-mocks', + changeDetection: ChangeDetectionStrategy.OnPush, }) -export class AppComponent { - title = 'app'; -} +export class AppComponent {} diff --git a/e2e/a5es5/src/app/app.component.css b/e2e/a5es5/src/app/app.component.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a5es5/src/app/app.component.html b/e2e/a5es5/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a5es5/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a5es5/src/app/app.component.ts b/e2e/a5es5/src/app/app.component.ts index 5c65edda89..9b6e0b1392 100644 --- a/e2e/a5es5/src/app/app.component.ts +++ b/e2e/a5es5/src/app/app.component.ts @@ -1,10 +1,8 @@ -import { Component } from '@angular/core'; +import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.css'], + template: 'ng-mocks', + changeDetection: ChangeDetectionStrategy.OnPush, }) -export class AppComponent { - title = 'app'; -} +export class AppComponent {} diff --git a/e2e/a6es2015/src/app/app.component.html b/e2e/a6es2015/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a6es2015/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a6es2015/src/app/app.component.scss b/e2e/a6es2015/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a6es2015/src/app/app.component.ts b/e2e/a6es2015/src/app/app.component.ts index 3e1b37a943..b268ce6c53 100644 --- a/e2e/a6es2015/src/app/app.component.ts +++ b/e2e/a6es2015/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a6es5/src/app/app.component.html b/e2e/a6es5/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a6es5/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a6es5/src/app/app.component.scss b/e2e/a6es5/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a6es5/src/app/app.component.ts b/e2e/a6es5/src/app/app.component.ts index 3e1b37a943..b268ce6c53 100644 --- a/e2e/a6es5/src/app/app.component.ts +++ b/e2e/a6es5/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a7es2015/src/app/app.component.html b/e2e/a7es2015/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a7es2015/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a7es2015/src/app/app.component.scss b/e2e/a7es2015/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a7es2015/src/app/app.component.ts b/e2e/a7es2015/src/app/app.component.ts index 3e1b37a943..b268ce6c53 100644 --- a/e2e/a7es2015/src/app/app.component.ts +++ b/e2e/a7es2015/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a7es5/src/app/app.component.html b/e2e/a7es5/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a7es5/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a7es5/src/app/app.component.scss b/e2e/a7es5/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a7es5/src/app/app.component.ts b/e2e/a7es5/src/app/app.component.ts index 3e1b37a943..b268ce6c53 100644 --- a/e2e/a7es5/src/app/app.component.ts +++ b/e2e/a7es5/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a8es2015/src/app/app.component.html b/e2e/a8es2015/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a8es2015/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a8es2015/src/app/app.component.scss b/e2e/a8es2015/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a8es2015/src/app/app.component.ts b/e2e/a8es2015/src/app/app.component.ts index 3e1b37a943..b268ce6c53 100644 --- a/e2e/a8es2015/src/app/app.component.ts +++ b/e2e/a8es2015/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a8es5/src/app/app.component.html b/e2e/a8es5/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a8es5/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a8es5/src/app/app.component.scss b/e2e/a8es5/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a8es5/src/app/app.component.ts b/e2e/a8es5/src/app/app.component.ts index 3e1b37a943..b268ce6c53 100644 --- a/e2e/a8es5/src/app/app.component.ts +++ b/e2e/a8es5/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a9es2015ivy/package-lock.json b/e2e/a9es2015ivy/package-lock.json index b2c2b2c66a..b87ba8a5b1 100644 --- a/e2e/a9es2015ivy/package-lock.json +++ b/e2e/a9es2015ivy/package-lock.json @@ -205,6 +205,22 @@ "resolved": "https://registry.npmjs.org/@angular/animations/-/animations-9.0.7.tgz", "integrity": "sha512-74gY7onajmmnksy5E0/32bFv3B9NuWxV64kqD15YjGrh8AWe1BHt5enQI+rJ2tO8m2DKnwZsctis6k0Kcy+YKQ==" }, + "@angular/cdk": { + "version": "9.2.4", + "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-9.2.4.tgz", + "integrity": "sha512-iw2+qHMXHYVC6K/fttHeNHIieSKiTEodVutZoOEcBu9rmRTGbLB26V/CRsfIRmA1RBk+uFYWc6UQZnMC3RdnJQ==", + "requires": { + "parse5": "^5.0.0" + }, + "dependencies": { + "parse5": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.1.tgz", + "integrity": "sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==", + "optional": true + } + } + }, "@angular/cli": { "version": "9.0.7", "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-9.0.7.tgz", @@ -368,6 +384,11 @@ "integrity": "sha512-IZG1kvw48JyFRy7bfMHqBixWrEHZmXmkP5DWsi5Tw6KusaczkMghI20BevCkodPcajXWHAUHNKyp1tlE3OnH0w==", "dev": true }, + "@angular/material": { + "version": "9.2.4", + "resolved": "https://registry.npmjs.org/@angular/material/-/material-9.2.4.tgz", + "integrity": "sha512-LkoTXE6B0slvMhvfZDdPWaz4yaYLkaAp5VSPunI9pxGsPxzqEV9e210wC1/sjG/76Nk8Ep7/2z9XKac8Q9bMwA==" + }, "@angular/platform-browser": { "version": "9.0.7", "resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-9.0.7.tgz", diff --git a/e2e/a9es2015ivy/package.json b/e2e/a9es2015ivy/package.json index 09ca680c24..13d9a11d99 100644 --- a/e2e/a9es2015ivy/package.json +++ b/e2e/a9es2015ivy/package.json @@ -20,10 +20,12 @@ }, "dependencies": { "@angular/animations": "~9.0.7", + "@angular/cdk": "~9.2.4", "@angular/common": "~9.0.7", "@angular/compiler": "~9.0.7", "@angular/core": "~9.0.7", "@angular/forms": "~9.0.7", + "@angular/material": "~9.2.4", "@angular/platform-browser": "~9.0.7", "@angular/platform-browser-dynamic": "~9.0.7", "@angular/router": "~9.0.7", diff --git a/e2e/a9es2015ivy/src/app/app.component.html b/e2e/a9es2015ivy/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a9es2015ivy/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a9es2015ivy/src/app/app.component.scss b/e2e/a9es2015ivy/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a9es2015ivy/src/app/app.component.ts b/e2e/a9es2015ivy/src/app/app.component.ts index 3e1b37a943..b268ce6c53 100644 --- a/e2e/a9es2015ivy/src/app/app.component.ts +++ b/e2e/a9es2015ivy/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a9es2015noivy/src/app/app.component.html b/e2e/a9es2015noivy/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a9es2015noivy/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a9es2015noivy/src/app/app.component.scss b/e2e/a9es2015noivy/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a9es2015noivy/src/app/app.component.ts b/e2e/a9es2015noivy/src/app/app.component.ts index 3e1b37a943..b268ce6c53 100644 --- a/e2e/a9es2015noivy/src/app/app.component.ts +++ b/e2e/a9es2015noivy/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a9es5ivy/src/app/app.component.html b/e2e/a9es5ivy/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a9es5ivy/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a9es5ivy/src/app/app.component.scss b/e2e/a9es5ivy/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a9es5ivy/src/app/app.component.ts b/e2e/a9es5ivy/src/app/app.component.ts index 3e1b37a943..b268ce6c53 100644 --- a/e2e/a9es5ivy/src/app/app.component.ts +++ b/e2e/a9es5ivy/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/e2e/a9es5noivy/src/app/app.component.html b/e2e/a9es5noivy/src/app/app.component.html deleted file mode 100644 index d6f5903e18..0000000000 --- a/e2e/a9es5noivy/src/app/app.component.html +++ /dev/null @@ -1 +0,0 @@ -ng-mocks diff --git a/e2e/a9es5noivy/src/app/app.component.scss b/e2e/a9es5noivy/src/app/app.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/a9es5noivy/src/app/app.component.ts b/e2e/a9es5noivy/src/app/app.component.ts index 3e1b37a943..b268ce6c53 100644 --- a/e2e/a9es5noivy/src/app/app.component.ts +++ b/e2e/a9es5noivy/src/app/app.component.ts @@ -2,8 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], + template: 'ng-mocks', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent {} diff --git a/lib/mock-component/mock-component.ts b/lib/mock-component/mock-component.ts index 89dfd76445..354b6a9513 100644 --- a/lib/mock-component/mock-component.ts +++ b/lib/mock-component/mock-component.ts @@ -110,20 +110,34 @@ export function MockComponent( template, }; - for (const providerDef of flatten(providers)) { - const provider = + let includeNgValueAccessor = true; + for (const providerDef of flatten(providers || [])) { + const provide = providerDef && typeof providerDef === 'object' && providerDef.provide ? providerDef.provide : providerDef; - if (options.providers && provider === NG_VALUE_ACCESSOR) { + if (includeNgValueAccessor && options.providers && provide === NG_VALUE_ACCESSOR) { + includeNgValueAccessor = false; options.providers.push({ multi: true, - provide: NG_VALUE_ACCESSOR, + provide, useExisting: forwardRef(() => ComponentMock), }); } - if (options.providers && provider === NG_VALIDATORS) { + if (options.providers && provide === NG_VALIDATORS) { + options.providers.push({ + multi: true, + provide, + useExisting: forwardRef(() => ComponentMock), + }); + } else if ( + includeNgValueAccessor && + options.providers && + provide !== providerDef && + providerDef.useExisting === component + ) { + includeNgValueAccessor = false; options.providers.push({ multi: true, - provide: NG_VALIDATORS, + provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => ComponentMock), }); } diff --git a/lib/mock-directive/mock-directive.ts b/lib/mock-directive/mock-directive.ts index cc0fe59433..978cf235e9 100644 --- a/lib/mock-directive/mock-directive.ts +++ b/lib/mock-directive/mock-directive.ts @@ -67,20 +67,20 @@ export function MockDirective(directive: Type): Type DirectiveMock), }); } - if (options.providers && provider === NG_VALIDATORS) { + if (options.providers && provide === NG_VALIDATORS) { options.providers.push({ multi: true, - provide: NG_VALIDATORS, + provide, useExisting: forwardRef(() => DirectiveMock), }); } diff --git a/tests/issue-157/components.spec.ts b/tests/issue-157/components.spec.ts new file mode 100644 index 0000000000..63c3030ab4 --- /dev/null +++ b/tests/issue-157/components.spec.ts @@ -0,0 +1,85 @@ +import { Component, NgModule } from '@angular/core'; +import { NG_VALUE_ACCESSOR } from '@angular/forms'; +import { MockComponent } from 'ng-mocks'; +import { directiveResolver } from 'ng-mocks/dist/lib/common/reflect'; + +@Component({ + selector: 'component', + template: '', +}) +export class ComponentDefault {} + +@Component({ + providers: [ + { + provide: NgModule, + useExisting: ComponentValueAccessor, + }, + ], + selector: 'component', + template: '', +}) +export class ComponentValueAccessor {} + +@Component({ + providers: [ + { + provide: NgModule, + useExisting: ComponentValueAccessorMulti, + }, + { + provide: Component, + useExisting: ComponentValueAccessorMulti, + }, + ], + selector: 'component', + template: '', +}) +export class ComponentValueAccessorMulti {} + +// if a component has a useExisting that points to itself we should provide it as NG_VALUE_ACCESSOR. +// perhaps it's a wrong approach, but that's a way how to mock mat-* components correctly. +describe('issue-157', () => { + it('ComponentDefault', () => { + const mock = MockComponent(ComponentDefault); + const { providers } = directiveResolver.resolve(mock); + expect(providers).toEqual([ + { + provide: ComponentDefault, + useExisting: jasmine.anything(), + }, + ]); + }); + + it('ComponentValueAccessor', () => { + const mock = MockComponent(ComponentValueAccessor); + const { providers } = directiveResolver.resolve(mock); + expect(providers).toEqual([ + { + provide: ComponentValueAccessor, + useExisting: jasmine.anything(), + }, + { + multi: true, + provide: NG_VALUE_ACCESSOR, + useExisting: jasmine.anything(), + }, + ]); + }); + + it('ComponentValueAccessorMulti', () => { + const mock = MockComponent(ComponentValueAccessorMulti); + const { providers } = directiveResolver.resolve(mock); + expect(providers).toEqual([ + { + provide: ComponentValueAccessorMulti, + useExisting: jasmine.anything(), + }, + { + multi: true, + provide: NG_VALUE_ACCESSOR, + useExisting: jasmine.anything(), + }, + ]); + }); +}); diff --git a/tslint.json b/tslint.json index d02364b1ec..fd4898efc9 100644 --- a/tslint.json +++ b/tslint.json @@ -5,6 +5,7 @@ "arrow-parens": false, "comment-format": false, "completed-docs": false, + "cyclomatic-complexity": false, "deprecation": false, "file-name-casing": false, "max-classes-per-file": false,