Skip to content

Commit

Permalink
Add example of TestBed component compiling manually in the component …
Browse files Browse the repository at this point in the history
…(Page2) as opposed to calling TestUtils closes #179
  • Loading branch information
lathonez committed Dec 8, 2016
1 parent b3dbde2 commit 51b5e23
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# 2.4.0 (2016-12-08)

### Features

* **Unit**: Add example of TestBed component compiling manually in the component (Page2) as opposed to calling TestUtils closes [#179](https://github.com/lathonez/clicker/issues/179) ([](https://github.com/lathonez/clicker/commit/))

### Bug Fixes

* **Unit**: Add mime type to karma.conf.js, closes [#178](https://github.com/lathonez/clicker/issues/178) ([5c0ffeb](https://github.com/lathonez/clicker/commit/5c0ffeb))
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 --code-coverage"
},
"version": "2.3.0",
"version": "2.4.0",
"dependencies": {
"@angular/common": "2.1.1",
"@angular/compiler": "2.1.1",
Expand Down
34 changes: 26 additions & 8 deletions src/pages/page2/page2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
import { ComponentFixture, async } from '@angular/core/testing';
import { TestUtils } from '../../test';
import { Page2 } from './page2';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { App, MenuController, NavController, Platform, Config, Keyboard, Form, IonicModule } from 'ionic-angular';
import { ConfigMock } from '../../mocks';
import { Page2 } from './page2';

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

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

beforeEach(async(() => TestUtils.beforeEachCompiler([Page2]).then(compiled => {
fixture = compiled.fixture;
instance = compiled.instance;
fixture.detectChanges();
})));
// demonstration on how to manually compile the test bed (as opposed to calling TestUtils)
beforeEach(async(() => {

TestBed.configureTestingModule({
declarations: [Page2],
providers: [
App, Platform, Form, Keyboard, MenuController, NavController,
{provide: Config, useClass: ConfigMock},
],
imports: [
FormsModule,
IonicModule,
ReactiveFormsModule,
],
})
.compileComponents().then(() => {
fixture = TestBed.createComponent(Page2);
instance = fixture;
fixture.detectChanges();
});
}));

afterEach(() => {
fixture.destroy();
Expand Down

0 comments on commit 51b5e23

Please sign in to comment.