Skip to content

Commit

Permalink
Add compileComponents to beforeEach, use ng-cli's tsconfig.json for t…
Browse files Browse the repository at this point in the history
…esting, closes #155
  • Loading branch information
lathonez committed Oct 30, 2016
1 parent d95e045 commit d59d968
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 38 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name="2.0.1"></a>
# 2.0.1 (2016-10-30)

### Bug Fixes

* **Unit**: Add compileComponents to beforeEach, use ng-cli's tsconfig.json for testing for #155 [#155](https://github.com/lathonez/clicker/issues/155) ([](https://github.com/lathonez/clicker/commit/))

<a name="2.0.0"></a>
# 2.0.0 (2016-10-16)

Expand Down
2 changes: 1 addition & 1 deletion angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "../tsconfig.json",
"tsconfig": "tsconfig.test.json",
"prefix": "app",
"mobile": false,
"styles": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"start": "ionic serve",
"test": "ng test"
},
"version": "2.0.0",
"version": "2.0.1",
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
Expand Down
24 changes: 15 additions & 9 deletions src/components/clickerButton/clickerButton.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TestUtils } from '../../test';
import { ClickerButton } from './clickerButton';
import { ClickerMock } from '../../models/clicker.mock';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { TestUtils } from '../../test';
import { ClickerButton } from './clickerButton';
import { ClickerMock } from '../../models/clicker.mock';

let fixture: ComponentFixture<ClickerButton> = null;
let instance: any = null;

describe('ClickerButton', () => {

beforeEach(() => {
TestUtils.configureIonicTestingModule([ClickerButton]);
fixture = TestBed.createComponent(ClickerButton);
instance = fixture.debugElement.componentInstance;
instance.clicker = new ClickerMock();
beforeEach(async(() => {
return TestUtils.configureIonicTestingModule([ClickerButton])
.compileComponents().then(() => {
fixture = TestBed.createComponent(ClickerButton);
instance = fixture.debugElement.componentInstance;
instance.clicker = new ClickerMock();
});
}));

afterEach(() => {
fixture.destroy();
});

it('initialises', () => {
Expand Down
28 changes: 17 additions & 11 deletions src/components/clickerForm/clickerForm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { FormBuilder } from '@angular/forms';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TestUtils } from '../../test';
import { ClickerForm } from './clickerForm';
import { FormBuilder } from '@angular/forms';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { TestUtils } from '../../test';
import { ClickerForm } from './clickerForm';

let fixture: ComponentFixture<ClickerForm> = null;
let instance: any = null;

describe('ClickerForm', () => {

beforeEach(() => {
TestUtils.configureIonicTestingModule([ClickerForm]);
fixture = TestBed.createComponent(ClickerForm);
instance = fixture.debugElement.componentInstance;
instance.clicker = { name: 'TEST CLICKER' };
instance.clicker.getCount = function(): number { return 10; };
fixture.autoDetectChanges(true);
beforeEach(async(() => {
return TestUtils.configureIonicTestingModule([ClickerForm])
.compileComponents().then(() => {
fixture = TestBed.createComponent(ClickerForm);
instance = fixture.debugElement.componentInstance;
instance.clicker = { name: 'TEST CLICKER' };
instance.clicker.getCount = function(): number { return 10; };
fixture.autoDetectChanges(true);
});
}));

afterEach(() => {
fixture.destroy();
});

it('initialises', () => {
Expand Down
22 changes: 14 additions & 8 deletions src/pages/clickerList/clickerList.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TestUtils } from '../../test';
import { ClickerList } from './clickerList';
import { ClickerButton, ClickerForm } from '../../components';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { TestUtils } from '../../test';
import { ClickerList } from './clickerList';
import { ClickerButton, ClickerForm } from '../../components';

let fixture: ComponentFixture<ClickerList> = null;
let instance: any = null;

describe('ClickerList', () => {

beforeEach(() => {
TestUtils.configureIonicTestingModule([ClickerList, ClickerForm, ClickerButton]);
fixture = TestBed.createComponent(ClickerList);
instance = fixture.debugElement.componentInstance;
beforeEach(async(() => {
return TestUtils.configureIonicTestingModule([ClickerList, ClickerForm, ClickerButton])
.compileComponents().then(() => {
fixture = TestBed.createComponent(ClickerList);
instance = fixture.debugElement.componentInstance;
});
}));

afterEach(() => {
fixture.destroy();
});

it('initialises', () => {
Expand Down
20 changes: 14 additions & 6 deletions src/pages/page2/page2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ let instance: any = null;

describe('Pages: Page2', () => {

beforeEach(() => {
TestUtils.configureIonicTestingModule([Page2]);
fixture = TestBed.createComponent(Page2);
instance = fixture.debugElement.componentInstance;
beforeEach(async(() => {
return TestUtils.configureIonicTestingModule([Page2])
.compileComponents().then(() => {
fixture = TestBed.createComponent(Page2);
instance = fixture.debugElement.componentInstance;
fixture.detectChanges();
});
}));

afterEach(() => {
fixture.destroy();
});

it('should create page2', async(() => {
it('should create page2', () => {
expect(fixture).toBeTruthy();
expect(instance).toBeTruthy();
}));
});
});
4 changes: 2 additions & 2 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Promise.all([

export class TestUtils {

public static configureIonicTestingModule(components: Array<any>): void {
TestBed.configureTestingModule({
public static configureIonicTestingModule(components: Array<any>): typeof TestBed {
return TestBed.configureTestingModule({
declarations: [
...components,
],
Expand Down
17 changes: 17 additions & 0 deletions src/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
]
}
}

0 comments on commit d59d968

Please sign in to comment.