diff --git a/index.ts b/index.ts index 154c194b14..7a01c90e30 100644 --- a/index.ts +++ b/index.ts @@ -1,3 +1,3 @@ export { MockComponent } from './lib/mock-component'; -export { MockDirective } from 'mock-directive'; +export { MockDirective } from './lib/mock-directive'; export { MockPipe } from 'mock-pipe'; diff --git a/karma-test-shim.ts b/karma-test-shim.ts new file mode 100644 index 0000000000..0dfa2fb94a --- /dev/null +++ b/karma-test-shim.ts @@ -0,0 +1,9 @@ +Error.stackTraceLimit = Infinity; + +import { getTestBed } from '@angular/core/testing'; +import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; + +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting() +); diff --git a/karma.conf.ts b/karma.conf.ts index 19909580f7..b9ba30f00b 100644 --- a/karma.conf.ts +++ b/karma.conf.ts @@ -14,6 +14,7 @@ module.exports = (config: any) => { 'node_modules/zone.js/dist/jasmine-patch.js', 'node_modules/zone.js/dist/async-test.js', 'node_modules/zone.js/dist/fake-async-test.js', + 'karma-test-shim.ts', { pattern: 'lib/**/*.ts' } ], frameworks: ['jasmine', 'karma-typescript'], diff --git a/lib/mock-component/mock-component.spec.ts b/lib/mock-component/mock-component.spec.ts index 751167f855..cb576a23b4 100644 --- a/lib/mock-component/mock-component.spec.ts +++ b/lib/mock-component/mock-component.spec.ts @@ -1,11 +1,7 @@ import { Component } from '@angular/core'; -import { async, ComponentFixture, getTestBed, TestBed } from '@angular/core/testing'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { FormsModule } from '@angular/forms'; import { By } from '@angular/platform-browser'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting -} from '@angular/platform-browser-dynamic/testing'; import { MockComponent } from './mock-component'; import { EmptyComponent } from './test-components/empty-component.component'; import { SimpleComponent } from './test-components/simple-component.component'; @@ -31,11 +27,6 @@ describe('MockComponent', () => { let component: ExampleComponentContainer; let fixture: ComponentFixture; - getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() - ); - beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ diff --git a/lib/mock-directive/index.ts b/lib/mock-directive/index.ts new file mode 100644 index 0000000000..fee4a8ec0c --- /dev/null +++ b/lib/mock-directive/index.ts @@ -0,0 +1 @@ +export { MockDirective } from './mock_directive'; diff --git a/lib/mock-directive/mock_directive.spec.ts b/lib/mock-directive/mock_directive.spec.ts index 02aa8a2827..653a9c69e2 100644 --- a/lib/mock-directive/mock_directive.spec.ts +++ b/lib/mock-directive/mock_directive.spec.ts @@ -1,11 +1,7 @@ import { Component, Directive, Input } from '@angular/core'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { FormControlDirective } from '@angular/forms'; -import { async, ComponentFixture, getTestBed, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting -} from '@angular/platform-browser-dynamic/testing'; import { MockDirective } from './mock_directive'; @Directive({ @@ -24,16 +20,11 @@ export class ExampleDirective {
` }) -export class ExampleComponentContainer {} +export class ExampleComponentContainer {} // tslint:disable-line:max-classes-per-file describe('MockComponent', () => { let fixture: ComponentFixture; - getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() - ); - beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ @@ -70,7 +61,7 @@ describe('MockComponent', () => { // Some angular directives set up their metadata in a different way than @Directive does // I found that FormControlDirective is one of those weird directives. // Since I don't know how they did it, I don't know how to test it except to write this - // test around a known-odd directive. + // Test around a known-odd directive. expect(() => { MockDirective(FormControlDirective); }).not.toThrow(); diff --git a/tslint.json b/tslint.json index 40d77341b2..b83599217e 100644 --- a/tslint.json +++ b/tslint.json @@ -3,6 +3,7 @@ "rules": { "completed-docs": false, "member-access": false, + "newline-before-return": false, "newline-per-chained-call": false, "no-any": false, "no-implicit-dependencies": [true, "dev"],