Skip to content

Commit

Permalink
fix: adding NG_VALUE_ACCESSOR for mat components
Browse files Browse the repository at this point in the history
closes #157
  • Loading branch information
satanTime committed Jul 10, 2020
1 parent 55a0031 commit 65175dd
Show file tree
Hide file tree
Showing 54 changed files with 157 additions and 68 deletions.
1 change: 0 additions & 1 deletion e2e/a10es2015ivy/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a10es2015ivy/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a10es2015noivy/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a10es2015noivy/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a10es5ivy/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a10es5ivy/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a10es5noivy/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a10es5noivy/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Empty file.
1 change: 0 additions & 1 deletion e2e/a5es2015/src/app/app.component.html

This file was deleted.

10 changes: 4 additions & 6 deletions e2e/a5es2015/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -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 {}
Empty file.
1 change: 0 additions & 1 deletion e2e/a5es5/src/app/app.component.html

This file was deleted.

10 changes: 4 additions & 6 deletions e2e/a5es5/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -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 {}
1 change: 0 additions & 1 deletion e2e/a6es2015/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a6es2015/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a6es5/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a6es5/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a7es2015/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a7es2015/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a7es5/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a7es5/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a8es2015/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a8es2015/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a8es5/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a8es5/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
21 changes: 21 additions & 0 deletions e2e/a9es2015ivy/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions e2e/a9es2015ivy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion e2e/a9es2015ivy/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a9es2015ivy/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a9es2015noivy/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a9es2015noivy/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a9es5ivy/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a9es5ivy/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion e2e/a9es5noivy/src/app/app.component.html

This file was deleted.

Empty file.
3 changes: 1 addition & 2 deletions e2e/a9es5noivy/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
26 changes: 20 additions & 6 deletions lib/mock-component/mock-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,34 @@ export function MockComponent<TComponent>(
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),
});
}
Expand Down
12 changes: 6 additions & 6 deletions lib/mock-directive/mock-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ export function MockDirective<TDirective>(directive: Type<TDirective>): Type<Moc
selector,
};

for (const providerDef of flatten(providers)) {
const provider =
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 (options.providers && provide === NG_VALUE_ACCESSOR) {
options.providers.push({
multi: true,
provide: NG_VALUE_ACCESSOR,
provide,
useExisting: forwardRef(() => 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),
});
}
Expand Down
Loading

0 comments on commit 65175dd

Please sign in to comment.