Skip to content

Commit

Permalink
fix: mock_direcive integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ike18t committed Feb 11, 2018
1 parent 5152ae8 commit 7f02f7b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -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';
9 changes: 9 additions & 0 deletions karma-test-shim.ts
Original file line number Diff line number Diff line change
@@ -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()
);
1 change: 1 addition & 0 deletions karma.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
11 changes: 1 addition & 10 deletions lib/mock-component/mock-component.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -31,11 +27,6 @@ describe('MockComponent', () => {
let component: ExampleComponentContainer;
let fixture: ComponentFixture<ExampleComponentContainer>;

getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
Expand Down
1 change: 1 addition & 0 deletions lib/mock-directive/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { MockDirective } from './mock_directive';
15 changes: 3 additions & 12 deletions lib/mock-directive/mock_directive.spec.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -24,16 +20,11 @@ export class ExampleDirective {
<div exampleDirective></div>
`
})
export class ExampleComponentContainer {}
export class ExampleComponentContainer {} // tslint:disable-line:max-classes-per-file

describe('MockComponent', () => {
let fixture: ComponentFixture<ExampleComponentContainer>;

getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 7f02f7b

Please sign in to comment.