From 8176fa573e81a49abb9940db9658284d23c04f14 Mon Sep 17 00:00:00 2001 From: MG Date: Fri, 22 May 2020 20:04:53 +0200 Subject: [PATCH] fix: improving types and linter closes #127 --- .../fixtures.ts | 61 ++++++++ .../test.spec.ts | 113 +++++++++++++++ .../fixtures.ts | 70 +++++++++ .../test.spec.ts | 135 ++++++++++++++++++ e2e/exports-only/fixtures.components.ts | 2 - e2e/exports-only/fixtures.modules.ts | 2 - .../fixtures.components.ts | 2 - e2e/internal-only-nested/fixtures.modules.ts | 2 - e2e/internal-only/fixtures.components.ts | 2 - e2e/internal-only/fixtures.modules.ts | 2 - .../fixtures.components.ts | 2 - e2e/internal-vs-external/fixtures.modules.ts | 2 - .../fixtures.components.ts | 2 - .../fixtures.modules.ts | 2 - .../fixtures.components.ts | 2 - .../fixtures.modules.ts | 3 +- e2e/nested-before-each/fixtures.components.ts | 2 - e2e/nested-before-each/fixtures.modules.ts | 2 - .../fixtures.components.ts | 3 +- .../fixtures.modules.ts | 2 - .../fixtures.services.ts | 2 - e2e/on-push/on-push.spec.ts | 2 - .../fixtures.components.ts | 3 +- .../fixtures.modules.ts | 2 - .../fixtures.services.ts | 2 - .../fixtures.components.ts | 3 +- .../fixtures.module.ts | 2 - .../fixtures.components.ts | 2 - e2e/shared-mocked-module/fixtures.modules.ts | 2 - examples/MockBuilder/fixtures.components.ts | 4 +- examples/MockBuilder/fixtures.directives.ts | 2 - examples/MockBuilder/fixtures.modules.ts | 2 - examples/MockBuilder/fixtures.pipes.ts | 2 - examples/MockBuilder/fixtures.services.ts | 2 - examples/MockBuilder/fixtures.tokens.ts | 2 - examples/NG_MOCKS/fixtures.components.ts | 4 +- examples/NG_MOCKS/fixtures.directives.ts | 2 - examples/NG_MOCKS/fixtures.modules.ts | 2 - examples/NG_MOCKS/fixtures.pipes.ts | 2 - examples/NG_MOCKS/fixtures.services.ts | 2 - examples/NG_MOCKS/fixtures.tokens.ts | 2 - lib/common/Mock.spec.ts | 2 - lib/common/Mock.ts | 2 - lib/common/decorate.ts | 4 +- lib/common/lib.ts | 9 +- lib/common/mock-of.decorator.spec.ts | 1 - lib/common/mock-of.decorator.ts | 2 +- lib/common/ng-mocks-universe.ts | 4 +- lib/mock-builder/mock-builder.ts | 4 +- lib/mock-component/mock-component.spec.ts | 2 - lib/mock-component/mock-component.ts | 3 +- .../simple-component.component.ts | 2 - lib/mock-declaration/mock-declaration.spec.ts | 2 - lib/mock-declaration/mock-declaration.ts | 4 +- lib/mock-directive/mock-directive.spec.ts | 2 - lib/mock-directive/mock-directive.ts | 19 ++- lib/mock-helper/mock-helper.spec.ts | 2 - lib/mock-helper/mock-helper.ts | 10 +- lib/mock-module/mock-module.spec.ts | 2 - lib/mock-module/mock-module.ts | 4 +- lib/mock-module/test-fixtures.ts | 2 - lib/mock-pipe/mock-pipe.spec.ts | 4 - lib/mock-pipe/mock-pipe.ts | 4 +- lib/mock-render/mock-render.fixtures.ts | 2 - lib/mock-render/mock-render.ts | 3 +- lib/mock-service/mock-service.spec.ts | 3 - tslint.json | 6 +- 67 files changed, 433 insertions(+), 132 deletions(-) create mode 100644 e2e/control-value-accessor-form-control/fixtures.ts create mode 100644 e2e/control-value-accessor-form-control/test.spec.ts create mode 100644 e2e/control-value-accessor-ng-model/fixtures.ts create mode 100644 e2e/control-value-accessor-ng-model/test.spec.ts diff --git a/e2e/control-value-accessor-form-control/fixtures.ts b/e2e/control-value-accessor-form-control/fixtures.ts new file mode 100644 index 0000000000..5bf4d5500f --- /dev/null +++ b/e2e/control-value-accessor-form-control/fixtures.ts @@ -0,0 +1,61 @@ +import { CommonModule } from '@angular/common'; +import { Component, forwardRef, NgModule } from '@angular/core'; +import { ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms'; + +@Component({ + selector: 'target', + template: '', +}) +export class TargetComponent { + public readonly control = new FormControl(); +} + +@Component({ + providers: [ + { + multi: true, + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => ControlComponent), + }, + ], + selector: 'control', + template: '', +}) +export class ControlComponent implements ControlValueAccessor { + public isDisabled = false; + public value: any; + public change: any = () => undefined; + + changeTouch(): void { + this.touch(); + } + + changeValue(obj: any): void { + this.change(obj); + } + + registerOnChange(fn: any): void { + this.change = fn; + } + + registerOnTouched(fn: any): void { + this.touch = fn; + } + + setDisabledState(isDisabled: boolean): void { + this.isDisabled = isDisabled; + } + + public touch: any = () => undefined; + + writeValue(obj: any): void { + this.value = obj; + } +} + +@NgModule({ + declarations: [TargetComponent, ControlComponent], + exports: [TargetComponent], + imports: [CommonModule, ReactiveFormsModule], +}) +export class TargetModule {} diff --git a/e2e/control-value-accessor-form-control/test.spec.ts b/e2e/control-value-accessor-form-control/test.spec.ts new file mode 100644 index 0000000000..aafdd7cecd --- /dev/null +++ b/e2e/control-value-accessor-form-control/test.spec.ts @@ -0,0 +1,113 @@ +import { ReactiveFormsModule } from '@angular/forms'; + +import { MockBuilder } from '../../lib/mock-builder'; +import { MockComponent } from '../../lib/mock-component'; +import { MockHelper } from '../../lib/mock-helper'; +import { MockRender } from '../../lib/mock-render'; + +import { ControlComponent, TargetComponent, TargetModule } from './fixtures'; + +// a real case to check possible behavior. +describe('control-value-accessor-form-control:real', () => { + beforeEach(() => MockBuilder(TargetComponent).keep(TargetModule)); + + it('respects our formControl', () => { + const fixture = MockRender(TargetComponent, {}, false); + const mock = MockHelper.findOrFail(fixture.debugElement, ControlComponent).componentInstance; + spyOn(mock, 'writeValue').and.callThrough(); + spyOn(mock, 'setDisabledState').and.callThrough(); + fixture.detectChanges(); + + // tslint:disable-next-line:no-null-keyword + expect(mock.writeValue).toHaveBeenCalledWith(null); + expect(mock.setDisabledState).not.toHaveBeenCalled(); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + + // checking via original component + fixture.point.componentInstance.control.setValue('test1'); + expect(mock.writeValue).toHaveBeenCalledWith('test1'); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + + fixture.point.componentInstance.control.setValue('test2'); + expect(mock.writeValue).toHaveBeenCalledWith('test2'); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + + // checking that touch works + mock.changeTouch(); + expect(fixture.point.componentInstance.control.touched).toBeTruthy(); + + // checking that reset works + fixture.point.componentInstance.control.markAsUntouched(); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + + // checking that disabled works + fixture.point.componentInstance.control.disable(); + expect(mock.setDisabledState).toHaveBeenCalledWith(true); + fixture.point.componentInstance.control.enable(); + expect(mock.setDisabledState).toHaveBeenCalledWith(false); + + // changeValue doesn't trigger anything else but the callback. Therefore it doesn't render new value. + // It only updates the original control's value. + mock.changeValue('test3'); + expect(mock.writeValue).not.toHaveBeenCalledWith('test3'); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + expect(fixture.point.componentInstance.control.value).toBe('test3'); + }); +}); + +// a way that ensures that a mocked component behaves the same way as real one. +describe('control-value-accessor-form-control:mock', () => { + beforeEach(() => MockBuilder(TargetComponent, TargetModule).keep(ReactiveFormsModule)); + + it('respects our formControl', () => { + const fixture = MockRender(TargetComponent, {}, false); + const mock = MockHelper.findOrFail(fixture.debugElement, MockComponent(ControlComponent)).componentInstance; + spyOn(mock, 'writeValue').and.callThrough(); + spyOn(mock, 'setDisabledState').and.callThrough(); + spyOn(mock, 'registerOnChange').and.callThrough(); + spyOn(mock, 'registerOnTouched').and.callThrough(); + fixture.detectChanges(); + + // tslint:disable-next-line:no-null-keyword + expect(mock.writeValue).toHaveBeenCalledWith(null); + expect(mock.setDisabledState).not.toHaveBeenCalled(); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + + // checking via original component + fixture.point.componentInstance.control.setValue('test1'); + expect(mock.writeValue).toHaveBeenCalledWith('test1'); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + + fixture.point.componentInstance.control.setValue('test2'); + expect(mock.writeValue).toHaveBeenCalledWith('test2'); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + + // checking that touch works + mock.__simulateTouch(); + expect(fixture.point.componentInstance.control.touched).toBeTruthy(); + fixture.point.componentInstance.control.markAsUntouched(); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + // a way through a spy + MockHelper.mockService(mock, 'registerOnTouched').calls.first().args[0](); + expect(fixture.point.componentInstance.control.touched).toBeTruthy(); + fixture.point.componentInstance.control.markAsUntouched(); + + // checking that disabled works + fixture.point.componentInstance.control.disable(); + expect(mock.setDisabledState).toHaveBeenCalledWith(true); + fixture.point.componentInstance.control.enable(); + expect(mock.setDisabledState).toHaveBeenCalledWith(false); + + // changeValue doesn't trigger anything else but the callback. Therefore it doesn't render new value. + // It only updates the original control's value. + mock.__simulateChange('test3'); + expect(mock.writeValue).not.toHaveBeenCalledWith('test3'); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + expect(fixture.point.componentInstance.control.value).toBe('test3'); + // a way through a spy + MockHelper.mockService(mock, 'registerOnChange').calls.first().args[0]('test4'); + expect(mock.writeValue).not.toHaveBeenCalledWith('test4'); + expect(fixture.point.componentInstance.control.touched).toBeFalsy(); + expect(fixture.point.componentInstance.control.value).toBe('test4'); + }); +}); diff --git a/e2e/control-value-accessor-ng-model/fixtures.ts b/e2e/control-value-accessor-ng-model/fixtures.ts new file mode 100644 index 0000000000..fa31d8dd0a --- /dev/null +++ b/e2e/control-value-accessor-ng-model/fixtures.ts @@ -0,0 +1,70 @@ +import { CommonModule } from '@angular/common'; +import { Component, forwardRef, NgModule } from '@angular/core'; +import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms'; + +@Component({ + selector: 'target', + template: '', +}) +export class TargetComponent { + public disabled = false; + public realValue: null | string = null; // tslint:disable-line:no-null-keyword + + public get value(): null | string { + return this.realValue; + } + + public set value(value: null | string) { + this.realValue = value; + } +} + +@Component({ + providers: [ + { + multi: true, + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => ControlComponent), + }, + ], + selector: 'control', + template: '', +}) +export class ControlComponent implements ControlValueAccessor { + public isDisabled = false; + public value: any; + public change: any = () => undefined; + + changeTouch(): void { + this.touch(); + } + + changeValue(obj: any): void { + this.change(obj); + } + + registerOnChange(fn: any): void { + this.change = fn; + } + + registerOnTouched(fn: any): void { + this.touch = fn; + } + + setDisabledState(isDisabled: boolean): void { + this.isDisabled = isDisabled; + } + + public touch: any = () => undefined; + + writeValue(obj: any): void { + this.value = obj; + } +} + +@NgModule({ + declarations: [TargetComponent, ControlComponent], + exports: [TargetComponent], + imports: [CommonModule, FormsModule], +}) +export class TargetModule {} diff --git a/e2e/control-value-accessor-ng-model/test.spec.ts b/e2e/control-value-accessor-ng-model/test.spec.ts new file mode 100644 index 0000000000..2f395c9f66 --- /dev/null +++ b/e2e/control-value-accessor-ng-model/test.spec.ts @@ -0,0 +1,135 @@ +import { FormsModule, NgModel } from '@angular/forms'; + +import { MockBuilder } from '../../lib/mock-builder'; +import { MockComponent } from '../../lib/mock-component'; +import { MockHelper } from '../../lib/mock-helper'; +import { MockRender } from '../../lib/mock-render'; + +import { ControlComponent, TargetComponent, TargetModule } from './fixtures'; + +// a real case to check possible behavior. +describe('control-value-accessor-ng-model:real', () => { + beforeEach(() => MockBuilder(TargetComponent).keep(TargetModule)); + + it('respects our ngModel', async () => { + const fixture = MockRender(TargetComponent, {}, false); + const mockElement = MockHelper.findOrFail(fixture.debugElement, ControlComponent); + const mock = mockElement.componentInstance; + spyOn(mock, 'writeValue').and.callThrough(); + spyOn(mock, 'setDisabledState').and.callThrough(); + const ngModel = MockHelper.getDirectiveOrFail(mockElement, NgModel); + fixture.detectChanges(); + await fixture.whenStable(); + + // tslint:disable-next-line:no-null-keyword + expect(mock.writeValue).toHaveBeenCalledWith(null); + expect(mock.setDisabledState).not.toHaveBeenCalled(); + expect(ngModel.touched).toBeFalsy(); + + // checking via original component + fixture.point.componentInstance.value = 'test1'; + fixture.detectChanges(); + await fixture.whenStable(); + expect(mock.writeValue).toHaveBeenCalledWith('test1'); + expect(ngModel.touched).toBeFalsy(); + + fixture.point.componentInstance.value = 'test2'; + fixture.detectChanges(); + await fixture.whenStable(); + expect(mock.writeValue).toHaveBeenCalledWith('test2'); + expect(ngModel.touched).toBeFalsy(); + + // checking that touch works + mock.changeTouch(); + expect(ngModel.touched).toBeTruthy(); + + // checking that reset works + ngModel.control.markAsUntouched(); + expect(ngModel.touched).toBeFalsy(); + + // checking that disabled works + fixture.point.componentInstance.disabled = true; + fixture.detectChanges(); + await fixture.whenStable(); + expect(mock.setDisabledState).toHaveBeenCalledWith(true); + fixture.point.componentInstance.disabled = false; + fixture.detectChanges(); + await fixture.whenStable(); + expect(mock.setDisabledState).toHaveBeenCalledWith(false); + + // changeValue doesn't trigger anything else but the callback. Therefore it doesn't render new value. + // It only updates the original control's value. + mock.changeValue('test3'); + expect(mock.writeValue).not.toHaveBeenCalledWith('test3'); + expect(ngModel.touched).toBeFalsy(); + expect(fixture.point.componentInstance.value).toBe('test3'); + }); +}); + +// a way that ensures that a mocked component behaves the same way as real one. +describe('control-value-accessor-ng-model:mock', () => { + beforeEach(() => MockBuilder(TargetComponent, TargetModule).keep(FormsModule)); + + it('respects our ngModel', async () => { + const fixture = MockRender(TargetComponent, {}, false); + const mockElement = MockHelper.findOrFail(fixture.debugElement, MockComponent(ControlComponent)); + const mock = mockElement.componentInstance; + spyOn(mock, 'writeValue').and.callThrough(); + spyOn(mock, 'setDisabledState').and.callThrough(); + spyOn(mock, 'registerOnChange').and.callThrough(); + spyOn(mock, 'registerOnTouched').and.callThrough(); + const ngModel = MockHelper.getDirectiveOrFail(mockElement, NgModel); + fixture.detectChanges(); + await fixture.whenStable(); + + // tslint:disable-next-line:no-null-keyword + expect(mock.writeValue).toHaveBeenCalledWith(null); + expect(mock.setDisabledState).not.toHaveBeenCalled(); + expect(ngModel.touched).toBeFalsy(); + + // checking via original component + fixture.point.componentInstance.value = 'test1'; + fixture.detectChanges(); + await fixture.whenStable(); + expect(mock.writeValue).toHaveBeenCalledWith('test1'); + expect(ngModel.touched).toBeFalsy(); + + fixture.point.componentInstance.value = 'test2'; + fixture.detectChanges(); + await fixture.whenStable(); + expect(mock.writeValue).toHaveBeenCalledWith('test2'); + expect(ngModel.touched).toBeFalsy(); + + // checking that touch works + mock.__simulateTouch(); + expect(ngModel.touched).toBeTruthy(); + ngModel.control.markAsUntouched(); + expect(ngModel.touched).toBeFalsy(); + // a way through a spy + MockHelper.mockService(mock, 'registerOnTouched').calls.first().args[0](); + expect(ngModel.touched).toBeTruthy(); + ngModel.control.markAsUntouched(); + + // checking that disabled works + fixture.point.componentInstance.disabled = true; + fixture.detectChanges(); + await fixture.whenStable(); + expect(mock.setDisabledState).toHaveBeenCalledWith(true); + fixture.point.componentInstance.disabled = false; + fixture.detectChanges(); + await fixture.whenStable(); + expect(mock.setDisabledState).toHaveBeenCalledWith(false); + + // changeValue doesn't trigger anything else but the callback. Therefore it doesn't render new value. + // It only updates the original control's value. + mock.__simulateChange('test3'); + expect(mock.writeValue).not.toHaveBeenCalledWith('test3'); + expect(ngModel.touched).toBeFalsy(); + expect(fixture.point.componentInstance.value).toBe('test3'); + // a way through a spy + MockHelper.mockService(mock, 'registerOnChange').calls.first().args[0]('test4'); + expect(mock.writeValue).not.toHaveBeenCalledWith('test4'); + expect(ngModel.touched).toBeFalsy(); + expect(ngModel.value).toBe('test4'); + }); +}); diff --git a/e2e/exports-only/fixtures.components.ts b/e2e/exports-only/fixtures.components.ts index c435958609..9fd4b87b11 100644 --- a/e2e/exports-only/fixtures.components.ts +++ b/e2e/exports-only/fixtures.components.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component } from '@angular/core'; @Component({ diff --git a/e2e/exports-only/fixtures.modules.ts b/e2e/exports-only/fixtures.modules.ts index 78ca23dfed..95e2906ecc 100644 --- a/e2e/exports-only/fixtures.modules.ts +++ b/e2e/exports-only/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; diff --git a/e2e/internal-only-nested/fixtures.components.ts b/e2e/internal-only-nested/fixtures.components.ts index c435958609..9fd4b87b11 100644 --- a/e2e/internal-only-nested/fixtures.components.ts +++ b/e2e/internal-only-nested/fixtures.components.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component } from '@angular/core'; @Component({ diff --git a/e2e/internal-only-nested/fixtures.modules.ts b/e2e/internal-only-nested/fixtures.modules.ts index 19e5b849f3..643509a790 100644 --- a/e2e/internal-only-nested/fixtures.modules.ts +++ b/e2e/internal-only-nested/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; diff --git a/e2e/internal-only/fixtures.components.ts b/e2e/internal-only/fixtures.components.ts index c435958609..9fd4b87b11 100644 --- a/e2e/internal-only/fixtures.components.ts +++ b/e2e/internal-only/fixtures.components.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component } from '@angular/core'; @Component({ diff --git a/e2e/internal-only/fixtures.modules.ts b/e2e/internal-only/fixtures.modules.ts index f68335ef9d..b9d4de82e8 100644 --- a/e2e/internal-only/fixtures.modules.ts +++ b/e2e/internal-only/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; diff --git a/e2e/internal-vs-external/fixtures.components.ts b/e2e/internal-vs-external/fixtures.components.ts index 8dfa011056..bc86a0d881 100644 --- a/e2e/internal-vs-external/fixtures.components.ts +++ b/e2e/internal-vs-external/fixtures.components.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component } from '@angular/core'; @Component({ diff --git a/e2e/internal-vs-external/fixtures.modules.ts b/e2e/internal-vs-external/fixtures.modules.ts index 58799f9cfb..f7c1d56d56 100644 --- a/e2e/internal-vs-external/fixtures.modules.ts +++ b/e2e/internal-vs-external/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; diff --git a/e2e/mock-builder-by-directive/fixtures.components.ts b/e2e/mock-builder-by-directive/fixtures.components.ts index c435958609..9fd4b87b11 100644 --- a/e2e/mock-builder-by-directive/fixtures.components.ts +++ b/e2e/mock-builder-by-directive/fixtures.components.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component } from '@angular/core'; @Component({ diff --git a/e2e/mock-builder-by-directive/fixtures.modules.ts b/e2e/mock-builder-by-directive/fixtures.modules.ts index fdc82f5960..430a37d058 100644 --- a/e2e/mock-builder-by-directive/fixtures.modules.ts +++ b/e2e/mock-builder-by-directive/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { NgModule } from '@angular/core'; import { InternalComponent } from './fixtures.components'; diff --git a/e2e/mock-builder-keeps-application-module/fixtures.components.ts b/e2e/mock-builder-keeps-application-module/fixtures.components.ts index 239d0d4493..d23ac6421a 100644 --- a/e2e/mock-builder-keeps-application-module/fixtures.components.ts +++ b/e2e/mock-builder-keeps-application-module/fixtures.components.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component } from '@angular/core'; @Component({ diff --git a/e2e/mock-builder-keeps-application-module/fixtures.modules.ts b/e2e/mock-builder-keeps-application-module/fixtures.modules.ts index f5e2d465e7..23534c3e82 100644 --- a/e2e/mock-builder-keeps-application-module/fixtures.modules.ts +++ b/e2e/mock-builder-keeps-application-module/fixtures.modules.ts @@ -1,6 +1,5 @@ -// tslint:disable:max-classes-per-file - import { APP_ID, InjectionToken, NgModule } from '@angular/core'; + import { TargetComponent } from './fixtures.components'; export const TARGET_TOKEN = new InjectionToken('TARGET_TOKEN'); diff --git a/e2e/nested-before-each/fixtures.components.ts b/e2e/nested-before-each/fixtures.components.ts index c435958609..9fd4b87b11 100644 --- a/e2e/nested-before-each/fixtures.components.ts +++ b/e2e/nested-before-each/fixtures.components.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component } from '@angular/core'; @Component({ diff --git a/e2e/nested-before-each/fixtures.modules.ts b/e2e/nested-before-each/fixtures.modules.ts index fdc82f5960..430a37d058 100644 --- a/e2e/nested-before-each/fixtures.modules.ts +++ b/e2e/nested-before-each/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { NgModule } from '@angular/core'; import { InternalComponent } from './fixtures.components'; diff --git a/e2e/normal-usage-after-mock-builder/fixtures.components.ts b/e2e/normal-usage-after-mock-builder/fixtures.components.ts index ba2d1ec9dd..78929f1109 100644 --- a/e2e/normal-usage-after-mock-builder/fixtures.components.ts +++ b/e2e/normal-usage-after-mock-builder/fixtures.components.ts @@ -1,6 +1,5 @@ -// tslint:disable:max-classes-per-file - import { Component } from '@angular/core'; + import { TargetService } from './fixtures.services'; @Component({ diff --git a/e2e/normal-usage-after-mock-builder/fixtures.modules.ts b/e2e/normal-usage-after-mock-builder/fixtures.modules.ts index f083e8c777..dcf1791fe4 100644 --- a/e2e/normal-usage-after-mock-builder/fixtures.modules.ts +++ b/e2e/normal-usage-after-mock-builder/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { NgModule } from '@angular/core'; import { RealComponent, TargetComponent } from './fixtures.components'; diff --git a/e2e/normal-usage-after-mock-builder/fixtures.services.ts b/e2e/normal-usage-after-mock-builder/fixtures.services.ts index 318ed1ec2e..1dcb2be9d6 100644 --- a/e2e/normal-usage-after-mock-builder/fixtures.services.ts +++ b/e2e/normal-usage-after-mock-builder/fixtures.services.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Injectable } from '@angular/core'; @Injectable() diff --git a/e2e/on-push/on-push.spec.ts b/e2e/on-push/on-push.spec.ts index 84420723b9..16cfa572cd 100644 --- a/e2e/on-push/on-push.spec.ts +++ b/e2e/on-push/on-push.spec.ts @@ -12,7 +12,6 @@ export class ItemListComponent { @Input() items: string[]; } -/* tslint:disable:max-classes-per-file */ @Component({ selector: 'item-list-wrapper', template: '', @@ -20,7 +19,6 @@ export class ItemListComponent { export class ItemListWrapperComponent { @Input() items: string[]; } -/* tslint:enable:max-classes-per-file */ describe('ChangeDetectionStrategy.OnPush:real', () => { let wrapper: ComponentFixture; diff --git a/e2e/provider-with-dependency/fixtures.components.ts b/e2e/provider-with-dependency/fixtures.components.ts index 9bacdd3309..ec2df5b5c2 100644 --- a/e2e/provider-with-dependency/fixtures.components.ts +++ b/e2e/provider-with-dependency/fixtures.components.ts @@ -1,6 +1,5 @@ -// tslint:disable:max-classes-per-file - import { Component } from '@angular/core'; + import { ServiceChild } from './fixtures.services'; @Component({ diff --git a/e2e/provider-with-dependency/fixtures.modules.ts b/e2e/provider-with-dependency/fixtures.modules.ts index 2fcc98fdaf..ec07026ec8 100644 --- a/e2e/provider-with-dependency/fixtures.modules.ts +++ b/e2e/provider-with-dependency/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { NgModule } from '@angular/core'; import { InternalComponent } from './fixtures.components'; diff --git a/e2e/provider-with-dependency/fixtures.services.ts b/e2e/provider-with-dependency/fixtures.services.ts index a53cba6992..15266dde1d 100644 --- a/e2e/provider-with-dependency/fixtures.services.ts +++ b/e2e/provider-with-dependency/fixtures.services.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Injectable } from '@angular/core'; @Injectable() diff --git a/e2e/rerender-rendered-content-child/fixtures.components.ts b/e2e/rerender-rendered-content-child/fixtures.components.ts index c4d8e04f5e..b1f1cfbcb0 100644 --- a/e2e/rerender-rendered-content-child/fixtures.components.ts +++ b/e2e/rerender-rendered-content-child/fixtures.components.ts @@ -1,6 +1,5 @@ -// tslint:disable:max-classes-per-file - import { Component, ContentChild, TemplateRef } from '@angular/core'; + import { staticFalse } from '../../tests'; @Component({ diff --git a/e2e/rerender-rendered-content-child/fixtures.module.ts b/e2e/rerender-rendered-content-child/fixtures.module.ts index e3ad7c23fa..df543f0a0c 100644 --- a/e2e/rerender-rendered-content-child/fixtures.module.ts +++ b/e2e/rerender-rendered-content-child/fixtures.module.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; diff --git a/e2e/shared-mocked-module/fixtures.components.ts b/e2e/shared-mocked-module/fixtures.components.ts index 1f05f380ca..16c311267e 100644 --- a/e2e/shared-mocked-module/fixtures.components.ts +++ b/e2e/shared-mocked-module/fixtures.components.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component } from '@angular/core'; @Component({ diff --git a/e2e/shared-mocked-module/fixtures.modules.ts b/e2e/shared-mocked-module/fixtures.modules.ts index fd18a9d31c..23252afd6b 100644 --- a/e2e/shared-mocked-module/fixtures.modules.ts +++ b/e2e/shared-mocked-module/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; diff --git a/examples/MockBuilder/fixtures.components.ts b/examples/MockBuilder/fixtures.components.ts index 26780702c4..e5c7a0c153 100644 --- a/examples/MockBuilder/fixtures.components.ts +++ b/examples/MockBuilder/fixtures.components.ts @@ -1,7 +1,7 @@ -// tslint:disable:max-classes-per-file - import { Component, ContentChild, Inject, Input, Optional, TemplateRef } from '@angular/core'; + import { staticFalse } from '../../tests'; + import { AnythingWeWant1, AnythingWeWant2, diff --git a/examples/MockBuilder/fixtures.directives.ts b/examples/MockBuilder/fixtures.directives.ts index 81cfafe8f2..6dbb2e86f8 100644 --- a/examples/MockBuilder/fixtures.directives.ts +++ b/examples/MockBuilder/fixtures.directives.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Directive } from '@angular/core'; @Directive({ diff --git a/examples/MockBuilder/fixtures.modules.ts b/examples/MockBuilder/fixtures.modules.ts index ee6af00949..264824c22b 100644 --- a/examples/MockBuilder/fixtures.modules.ts +++ b/examples/MockBuilder/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { HttpClientModule } from '@angular/common/http'; import { NgModule } from '@angular/core'; diff --git a/examples/MockBuilder/fixtures.pipes.ts b/examples/MockBuilder/fixtures.pipes.ts index 025ab36ab1..a1034148cb 100644 --- a/examples/MockBuilder/fixtures.pipes.ts +++ b/examples/MockBuilder/fixtures.pipes.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ diff --git a/examples/MockBuilder/fixtures.services.ts b/examples/MockBuilder/fixtures.services.ts index 93e5ffd732..4fb36c910a 100644 --- a/examples/MockBuilder/fixtures.services.ts +++ b/examples/MockBuilder/fixtures.services.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Injectable } from '@angular/core'; @Injectable() diff --git a/examples/MockBuilder/fixtures.tokens.ts b/examples/MockBuilder/fixtures.tokens.ts index 00f93ff489..8d527302f7 100644 --- a/examples/MockBuilder/fixtures.tokens.ts +++ b/examples/MockBuilder/fixtures.tokens.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { InjectionToken } from '@angular/core'; export const INJECTION_TOKEN_WE_DONT_WANT_TO_MOCK = new InjectionToken('INJECTION_TOKEN_WE_DONT_WANT_TO_MOCK'); diff --git a/examples/NG_MOCKS/fixtures.components.ts b/examples/NG_MOCKS/fixtures.components.ts index 6422604453..b15d870dec 100644 --- a/examples/NG_MOCKS/fixtures.components.ts +++ b/examples/NG_MOCKS/fixtures.components.ts @@ -1,7 +1,7 @@ -// tslint:disable:max-classes-per-file - import { Component, ContentChild, Inject, Input, Optional, TemplateRef } from '@angular/core'; + import { staticFalse } from '../../tests'; + import { AnythingWeWant1, AnythingWeWant2, diff --git a/examples/NG_MOCKS/fixtures.directives.ts b/examples/NG_MOCKS/fixtures.directives.ts index 81cfafe8f2..6dbb2e86f8 100644 --- a/examples/NG_MOCKS/fixtures.directives.ts +++ b/examples/NG_MOCKS/fixtures.directives.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Directive } from '@angular/core'; @Directive({ diff --git a/examples/NG_MOCKS/fixtures.modules.ts b/examples/NG_MOCKS/fixtures.modules.ts index ee6af00949..264824c22b 100644 --- a/examples/NG_MOCKS/fixtures.modules.ts +++ b/examples/NG_MOCKS/fixtures.modules.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { HttpClientModule } from '@angular/common/http'; import { NgModule } from '@angular/core'; diff --git a/examples/NG_MOCKS/fixtures.pipes.ts b/examples/NG_MOCKS/fixtures.pipes.ts index 025ab36ab1..a1034148cb 100644 --- a/examples/NG_MOCKS/fixtures.pipes.ts +++ b/examples/NG_MOCKS/fixtures.pipes.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ diff --git a/examples/NG_MOCKS/fixtures.services.ts b/examples/NG_MOCKS/fixtures.services.ts index 93e5ffd732..4fb36c910a 100644 --- a/examples/NG_MOCKS/fixtures.services.ts +++ b/examples/NG_MOCKS/fixtures.services.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Injectable } from '@angular/core'; @Injectable() diff --git a/examples/NG_MOCKS/fixtures.tokens.ts b/examples/NG_MOCKS/fixtures.tokens.ts index 00f93ff489..8d527302f7 100644 --- a/examples/NG_MOCKS/fixtures.tokens.ts +++ b/examples/NG_MOCKS/fixtures.tokens.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { InjectionToken } from '@angular/core'; export const INJECTION_TOKEN_WE_DONT_WANT_TO_MOCK = new InjectionToken('INJECTION_TOKEN_WE_DONT_WANT_TO_MOCK'); diff --git a/lib/common/Mock.spec.ts b/lib/common/Mock.spec.ts index eeddfcda50..34b1e2a3c2 100644 --- a/lib/common/Mock.spec.ts +++ b/lib/common/Mock.spec.ts @@ -1,5 +1,3 @@ -/* tslint:disable: max-classes-per-file */ - import { Component, Directive, NgModule, Pipe, PipeTransform } from '@angular/core'; import { MockComponent } from '../mock-component'; diff --git a/lib/common/Mock.ts b/lib/common/Mock.ts index 6b8824d41a..e2a47f8732 100644 --- a/lib/common/Mock.ts +++ b/lib/common/Mock.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { EventEmitter } from '@angular/core'; import { ControlValueAccessor } from '@angular/forms'; diff --git a/lib/common/decorate.ts b/lib/common/decorate.ts index ccbdffc95a..a1e364284e 100644 --- a/lib/common/decorate.ts +++ b/lib/common/decorate.ts @@ -1,4 +1,6 @@ -import { ContentChild, ContentChildren, Input, Output, Query, Type, ViewChild, ViewChildren } from '@angular/core'; +import { ContentChild, ContentChildren, Input, Output, Query, ViewChild, ViewChildren } from '@angular/core'; + +import { Type } from './lib'; // Looks like an A9 bug, that queries from @Component aren't processed. // Also we have to pass prototype, not the class. diff --git a/lib/common/lib.ts b/lib/common/lib.ts index be7e6d49a0..76b755f988 100644 --- a/lib/common/lib.ts +++ b/lib/common/lib.ts @@ -1,4 +1,4 @@ -import { InjectionToken, ModuleWithProviders, PipeTransform, Type } from '@angular/core'; +import { InjectionToken, ModuleWithProviders, PipeTransform } from '@angular/core'; import { getTestBed } from '@angular/core/testing'; import { MockedComponent } from '../mock-component'; @@ -9,6 +9,13 @@ import { MockedPipe } from '../mock-pipe'; import { ngMocksUniverse } from './ng-mocks-universe'; import { jitReflector } from './reflect'; +// tslint:disable-next-line:interface-name +export interface AbstractType extends Function { + prototype: T; +} + +export type Type = new (...args: any[]) => T; + export const NG_MOCKS = new InjectionToken>('NG_MOCKS'); /** diff --git a/lib/common/mock-of.decorator.spec.ts b/lib/common/mock-of.decorator.spec.ts index 4ce0ca7626..180bdd6c4b 100644 --- a/lib/common/mock-of.decorator.spec.ts +++ b/lib/common/mock-of.decorator.spec.ts @@ -1,4 +1,3 @@ -/* tslint:disable: max-classes-per-file */ import { MockOf } from './mock-of.decorator'; describe('DebuggableMock', () => { diff --git a/lib/common/mock-of.decorator.ts b/lib/common/mock-of.decorator.ts index 66e4f055ca..479c75dcc5 100644 --- a/lib/common/mock-of.decorator.ts +++ b/lib/common/mock-of.decorator.ts @@ -1,4 +1,4 @@ -import { Type } from '@angular/core'; +import { Type } from './lib'; // This helps with debugging in the browser. Decorating mock classes with this // will change the display-name of the class to 'MockOf-` so our diff --git a/lib/common/ng-mocks-universe.ts b/lib/common/ng-mocks-universe.ts index 006539a9bf..f29e037650 100644 --- a/lib/common/ng-mocks-universe.ts +++ b/lib/common/ng-mocks-universe.ts @@ -1,4 +1,6 @@ -import { InjectionToken, Type } from '@angular/core'; +import { InjectionToken } from '@angular/core'; + +import { Type } from './lib'; /** * Can be changed any time. diff --git a/lib/mock-builder/mock-builder.ts b/lib/mock-builder/mock-builder.ts index 85a935066d..6ca4736224 100644 --- a/lib/mock-builder/mock-builder.ts +++ b/lib/mock-builder/mock-builder.ts @@ -1,9 +1,9 @@ // tslint:disable:unified-signatures -import { InjectionToken, ModuleWithProviders, NgModule, PipeTransform, Provider, Type } from '@angular/core'; +import { InjectionToken, ModuleWithProviders, NgModule, PipeTransform, Provider } from '@angular/core'; import { TestBed } from '@angular/core/testing'; -import { flatten, isNgDef, isNgInjectionToken, NG_MOCKS } from '../common'; +import { flatten, isNgDef, isNgInjectionToken, NG_MOCKS, Type } from '../common'; import { ngMocksUniverse } from '../common/ng-mocks-universe'; import { MockComponent } from '../mock-component'; import { MockDirective } from '../mock-directive'; diff --git a/lib/mock-component/mock-component.spec.ts b/lib/mock-component/mock-component.spec.ts index fd96fc2e5f..3cdaa57ea3 100644 --- a/lib/mock-component/mock-component.spec.ts +++ b/lib/mock-component/mock-component.spec.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component, ContentChild, diff --git a/lib/mock-component/mock-component.ts b/lib/mock-component/mock-component.ts index 7d3178f7da..89789b8e23 100644 --- a/lib/mock-component/mock-component.ts +++ b/lib/mock-component/mock-component.ts @@ -6,14 +6,13 @@ import { forwardRef, Query, TemplateRef, - Type, ViewChild, ViewContainerRef, } from '@angular/core'; import { getTestBed } from '@angular/core/testing'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; -import { getMockedNgDefOf, MockControlValueAccessor, MockOf } from '../common'; +import { getMockedNgDefOf, MockControlValueAccessor, MockOf, Type } from '../common'; import { decorateInputs, decorateOutputs, decorateQueries } from '../common/decorate'; import { ngMocksUniverse } from '../common/ng-mocks-universe'; import { directiveResolver } from '../common/reflect'; diff --git a/lib/mock-component/test-components/simple-component.component.ts b/lib/mock-component/test-components/simple-component.component.ts index 18d10d8898..14e5e34df4 100644 --- a/lib/mock-component/test-components/simple-component.component.ts +++ b/lib/mock-component/test-components/simple-component.component.ts @@ -8,7 +8,6 @@ export class BaseSimpleComponent { @Output() someOutput2: EventEmitter; } -/* tslint:disable:max-classes-per-file */ @Component({ exportAs: 'seeimple', selector: 'simple-component', @@ -20,4 +19,3 @@ export class SimpleComponent extends BaseSimpleComponent { @HostBinding('class.someClass') @Input() someInput3: boolean; @Output() someOutput1: EventEmitter; } -/* tslint:enable:max-classes-per-file */ diff --git a/lib/mock-declaration/mock-declaration.spec.ts b/lib/mock-declaration/mock-declaration.spec.ts index a29b414a67..2a3329da12 100644 --- a/lib/mock-declaration/mock-declaration.spec.ts +++ b/lib/mock-declaration/mock-declaration.spec.ts @@ -2,13 +2,11 @@ import { Component } from '@angular/core'; import { MockDeclaration } from './mock-declaration'; -// tslint:disable:max-classes-per-file @Component({ selector: 'empty-template-container', template: '', }) export class EmptyTemplateContainer {} -// tslint:enable:max-classes-per-file describe('MockDeclaration', () => { it('should process components with an empty template correctly', () => { diff --git a/lib/mock-declaration/mock-declaration.ts b/lib/mock-declaration/mock-declaration.ts index 2cab8d3bbc..ae1577f6d2 100644 --- a/lib/mock-declaration/mock-declaration.ts +++ b/lib/mock-declaration/mock-declaration.ts @@ -1,6 +1,4 @@ -import { Type } from '@angular/core'; - -import { isNgDef } from '../common'; +import { isNgDef, Type } from '../common'; import { MockComponent, MockedComponent } from '../mock-component'; import { MockDirective, MockedDirective } from '../mock-directive'; import { MockedPipe, MockPipe } from '../mock-pipe'; diff --git a/lib/mock-directive/mock-directive.spec.ts b/lib/mock-directive/mock-directive.spec.ts index 244a917a15..5a321a7cf7 100644 --- a/lib/mock-directive/mock-directive.spec.ts +++ b/lib/mock-directive/mock-directive.spec.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component, ContentChild, diff --git a/lib/mock-directive/mock-directive.ts b/lib/mock-directive/mock-directive.ts index 6b005fd901..6c943638aa 100644 --- a/lib/mock-directive/mock-directive.ts +++ b/lib/mock-directive/mock-directive.ts @@ -1,16 +1,8 @@ -import { - Directive, - ElementRef, - forwardRef, - OnInit, - Optional, - TemplateRef, - Type, - ViewContainerRef, -} from '@angular/core'; +import { Directive, ElementRef, forwardRef, OnInit, Optional, TemplateRef, ViewContainerRef } from '@angular/core'; import { getTestBed } from '@angular/core/testing'; +import { NG_VALUE_ACCESSOR } from '@angular/forms'; -import { getMockedNgDefOf, MockControlValueAccessor, MockOf } from '../common'; +import { getMockedNgDefOf, MockControlValueAccessor, MockOf, Type } from '../common'; import { decorateInputs, decorateOutputs, decorateQueries } from '../common/decorate'; import { ngMocksUniverse } from '../common/ng-mocks-universe'; import { directiveResolver } from '../common/reflect'; @@ -56,6 +48,11 @@ export function MockDirective(directive: Type): Type DirectiveMock), + }, { provide: directive, useExisting: forwardRef(() => DirectiveMock), diff --git a/lib/mock-helper/mock-helper.spec.ts b/lib/mock-helper/mock-helper.spec.ts index 08abaf76ce..ef4728a58a 100644 --- a/lib/mock-helper/mock-helper.spec.ts +++ b/lib/mock-helper/mock-helper.spec.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { Component, Directive, EventEmitter, Input, Output } from '@angular/core'; import { async, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; diff --git a/lib/mock-helper/mock-helper.ts b/lib/mock-helper/mock-helper.ts index b3a8e8d8e5..879be24487 100644 --- a/lib/mock-helper/mock-helper.ts +++ b/lib/mock-helper/mock-helper.ts @@ -1,8 +1,8 @@ /* tslint:disable:variable-name unified-signatures */ -import { Type } from '@angular/core'; import { By } from '@angular/platform-browser'; +import { AbstractType, Type } from '../common'; import { MockedDebugElement, MockedDebugNode } from '../mock-render'; import { MockedFunction, mockServiceHelper } from '../mock-service'; @@ -19,16 +19,24 @@ function nestedCheck(result: T[], node: MockedDebugNode, callback: (node: Moc export const MockHelper: { find(debugElement: MockedDebugElement, component: Type): null | MockedDebugElement; + find(debugElement: MockedDebugElement, component: AbstractType): null | MockedDebugElement; find(debugElement: MockedDebugElement, cssSelector: string): null | MockedDebugElement; findAll(debugElement: MockedDebugElement, component: Type): Array>; + findAll(debugElement: MockedDebugElement, component: AbstractType): Array>; findAll(debugElement: MockedDebugElement, cssSelector: string): Array>; findDirective(debugNode: MockedDebugNode, directive: Type): undefined | T; + findDirective(debugNode: MockedDebugNode, directive: AbstractType): undefined | T; findDirectiveOrFail(debugNode: MockedDebugNode, directive: Type): T; + findDirectiveOrFail(debugNode: MockedDebugNode, directive: AbstractType): T; findDirectives(debugNode: MockedDebugNode, directive: Type): T[]; + findDirectives(debugNode: MockedDebugNode, directive: AbstractType): T[]; findOrFail(debugElement: MockedDebugElement, component: Type): MockedDebugElement; + findOrFail(debugElement: MockedDebugElement, component: AbstractType): MockedDebugElement; findOrFail(debugElement: MockedDebugElement, cssSelector: string): MockedDebugElement; getDirective(debugNode: MockedDebugNode, directive: Type): undefined | T; + getDirective(debugNode: MockedDebugNode, directive: AbstractType): undefined | T; getDirectiveOrFail(debugNode: MockedDebugNode, directive: Type): T; + getDirectiveOrFail(debugNode: MockedDebugNode, directive: AbstractType): T; mockService(instance: any, name: string, style?: 'get' | 'set'): T; } = { getDirectiveOrFail: (debugNode: MockedDebugNode, directive: Type): T => { diff --git a/lib/mock-module/mock-module.spec.ts b/lib/mock-module/mock-module.spec.ts index 482f11bdd5..5dbaa3be1c 100644 --- a/lib/mock-module/mock-module.spec.ts +++ b/lib/mock-module/mock-module.spec.ts @@ -1,5 +1,3 @@ -/* tslint:disable:max-classes-per-file */ - import { CommonModule } from '@angular/common'; import { HTTP_INTERCEPTORS } from '@angular/common/http'; import { APP_INITIALIZER, ApplicationModule, Component, InjectionToken, NgModule } from '@angular/core'; diff --git a/lib/mock-module/mock-module.ts b/lib/mock-module/mock-module.ts index b8d2220914..b1b3df4db9 100644 --- a/lib/mock-module/mock-module.ts +++ b/lib/mock-module/mock-module.ts @@ -1,8 +1,8 @@ import { CommonModule } from '@angular/common'; -import { ApplicationModule, ModuleWithProviders, NgModule, Provider, Type } from '@angular/core'; +import { ApplicationModule, ModuleWithProviders, NgModule, Provider } from '@angular/core'; import { getTestBed } from '@angular/core/testing'; -import { flatten, getMockedNgDefOf, isNgDef, isNgModuleDefWithProviders, Mock, MockOf } from '../common'; +import { flatten, getMockedNgDefOf, isNgDef, isNgModuleDefWithProviders, Mock, MockOf, Type } from '../common'; import { ngMocksUniverse } from '../common/ng-mocks-universe'; import { ngModuleResolver } from '../common/reflect'; import { MockComponent } from '../mock-component'; diff --git a/lib/mock-module/test-fixtures.ts b/lib/mock-module/test-fixtures.ts index 08abd82871..567c0154df 100644 --- a/lib/mock-module/test-fixtures.ts +++ b/lib/mock-module/test-fixtures.ts @@ -1,5 +1,3 @@ -/* tslint:disable:max-classes-per-file */ - import { CommonModule } from '@angular/common'; import { Component, diff --git a/lib/mock-pipe/mock-pipe.spec.ts b/lib/mock-pipe/mock-pipe.spec.ts index bc71b03476..7593c566c7 100644 --- a/lib/mock-pipe/mock-pipe.spec.ts +++ b/lib/mock-pipe/mock-pipe.spec.ts @@ -9,8 +9,6 @@ export class ExamplePipe implements PipeTransform { transform = (args: string): string => 'hi'; } -// tslint:disable:max-classes-per-file - @Pipe({ name: 'anotherMockedPipe' }) export class AnotherExamplePipe implements PipeTransform { transform = (args: string): string => 'hi'; @@ -27,8 +25,6 @@ export class ExampleComponent { someStuff = 'bah'; } -// tslint:enable:max-classes-per-file - describe('MockPipe', () => { let fixture: ComponentFixture; diff --git a/lib/mock-pipe/mock-pipe.ts b/lib/mock-pipe/mock-pipe.ts index afed08b706..06ce9b7350 100644 --- a/lib/mock-pipe/mock-pipe.ts +++ b/lib/mock-pipe/mock-pipe.ts @@ -1,7 +1,7 @@ -import { Pipe, PipeTransform, Type } from '@angular/core'; +import { Pipe, PipeTransform } from '@angular/core'; import { getTestBed } from '@angular/core/testing'; -import { getMockedNgDefOf, Mock, MockOf } from '../common'; +import { getMockedNgDefOf, Mock, MockOf, Type } from '../common'; import { ngMocksUniverse } from '../common/ng-mocks-universe'; import { pipeResolver } from '../common/reflect'; diff --git a/lib/mock-render/mock-render.fixtures.ts b/lib/mock-render/mock-render.fixtures.ts index 727ce070b7..c7a73ef855 100644 --- a/lib/mock-render/mock-render.fixtures.ts +++ b/lib/mock-render/mock-render.fixtures.ts @@ -1,5 +1,3 @@ -// tslint:disable:max-classes-per-file - import { DOCUMENT } from '@angular/common'; import { Component, EventEmitter, Inject, Input, Output } from '@angular/core'; diff --git a/lib/mock-render/mock-render.ts b/lib/mock-render/mock-render.ts index 67570a2266..a1ff714fd2 100644 --- a/lib/mock-render/mock-render.ts +++ b/lib/mock-render/mock-render.ts @@ -1,8 +1,9 @@ // tslint:disable:unified-signatures -import { Component, DebugElement, DebugNode, Provider, Type } from '@angular/core'; +import { Component, DebugElement, DebugNode, Provider } from '@angular/core'; import { ComponentFixture, getTestBed, TestBed } from '@angular/core/testing'; +import { Type } from '../common'; import { directiveResolver } from '../common/reflect'; // A5 and its TS 2.4 don't support Omit, that's why we need the magic below. diff --git a/lib/mock-service/mock-service.spec.ts b/lib/mock-service/mock-service.spec.ts index 9985dbf517..bb0b53b500 100644 --- a/lib/mock-service/mock-service.spec.ts +++ b/lib/mock-service/mock-service.spec.ts @@ -4,7 +4,6 @@ import { MockHelper } from '../mock-helper'; import { MockService } from './mock-service'; -// tslint:disable:max-classes-per-file class DeepParentClass { public deepParentMethodName = 'deepParentMethod'; @@ -58,8 +57,6 @@ class GetterSetterMethodHuetod { } } -// tslint:enable:max-classes-per-file - describe('MockService', () => { it('should convert boolean, number, string, null and undefined to undefined', () => { expect(MockService(true)).toBeUndefined(); diff --git a/tslint.json b/tslint.json index 87a30fcaa9..4bfbadacc0 100644 --- a/tslint.json +++ b/tslint.json @@ -3,19 +3,21 @@ "rules": { "align": false, "arrow-parens": false, - "completed-docs": false, "comment-format": false, + "completed-docs": false, "deprecation": false, "file-name-casing": false, + "max-classes-per-file": false, "member-access": false, "newline-before-return": false, "newline-per-chained-call": false, "no-any": false, "no-disabled-tests": true, "no-empty": false, - "no-implicit-dependencies": [true, "dev", ["ng-mocks"]], "no-floating-promises": false, "no-focused-tests": true, + "no-implicit-dependencies": [true, "dev", ["ng-mocks"]], + "no-inferred-empty-object-type": false, "no-submodule-imports": false, "no-unbound-method": false, "no-unsafe-any": false,