Skip to content

Commit 48a695e

Browse files
committed
chore(tests): update specs with TestBed
Close #1766 Close #1846
1 parent 339af33 commit 48a695e

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* tslint:disable:no-unused-variable */
22

3-
import { By } from '@angular/platform-browser';
4-
import { DebugElement } from '@angular/core';
5-
import { addProviders, async, inject } from '@angular/core/testing';
3+
import { TestBed, async } from '@angular/core/testing';
64
import { <%= classifiedModuleName %>Component } from './<%= dasherizedModuleName %>.component';
75

86
describe('Component: <%= classifiedModuleName %>', () => {

addon/ng2/blueprints/directive/files/__path__/__name__.directive.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* tslint:disable:no-unused-variable */
22

3-
import { addProviders, async, inject } from '@angular/core/testing';
3+
import { TestBed, async } from '@angular/core/testing';
44
import { <%= classifiedModuleName %> } from './<%= dasherizedModuleName %>.directive';
55

66
describe('Directive: <%= classifiedModuleName %>', () => {

addon/ng2/blueprints/module/files/__path__/__name__.module.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* tslint:disable:no-unused-variable */
22

3+
import { TestBed, async } from '@angular/core/testing';
34
import <%= classifiedModuleName %>Module from './<%= dasherizedModuleName %>.module';
45

56
describe('<%= classifiedModuleName %>Module', () => {
Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
/* tslint:disable:no-unused-variable */
22

3-
import { addProviders, async, inject } from '@angular/core/testing';
3+
import { TestBed, async } from '@angular/core/testing';
44
import { AppComponent } from './app.component';
55

66
describe('App: <%= jsComponentName %>', () => {
77
beforeEach(() => {
8-
addProviders([AppComponent]);
8+
TestBed.configureTestingModule({
9+
declarations: [
10+
AppComponent
11+
],
12+
});
913
});
1014

11-
it('should create the app',
12-
inject([AppComponent], (app: AppComponent) => {
13-
expect(app).toBeTruthy();
14-
}));
15+
it('should create the app', async(() => {
16+
let fixture = TestBed.createComponent(AppComponent);
17+
let app = fixture.debugElement.componentInstance;
18+
expect(app).toBeTruthy();
19+
}));
1520

16-
it('should have as title \'app works!\'',
17-
inject([AppComponent], (app: AppComponent) => {
18-
expect(app.title).toEqual('app works!');
19-
}));
21+
it(`should have as title 'app works!'`, async(() => {
22+
let fixture = TestBed.createComponent(AppComponent);
23+
let app = fixture.debugElement.componentInstance;
24+
expect(app.title).toEqual('app works!');
25+
}));
26+
27+
it('should render title in a h1 tag', async(() => {
28+
let fixture = TestBed.createComponent(AppComponent);
29+
fixture.detectChanges();
30+
let compiled = fixture.debugElement.nativeElement;
31+
expect(compiled.querySelector('h1').textContent).toContain('app works!');
32+
}));
2033
});

addon/ng2/blueprints/pipe/files/__path__/__name__.pipe.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* tslint:disable:no-unused-variable */
22

3-
import { addProviders, async, inject } from '@angular/core/testing';
3+
import { TestBed, async } from '@angular/core/testing';
44
import { <%= classifiedModuleName %>Pipe } from './<%= dasherizedModuleName %>.pipe';
55

66
describe('Pipe: <%= classifiedModuleName %>', () => {
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/* tslint:disable:no-unused-variable */
22

3-
import { addProviders, async, inject } from '@angular/core/testing';
3+
import { TestBed, async, inject } from '@angular/core/testing';
44
import { <%= classifiedModuleName %>Service } from './<%= dasherizedModuleName %>.service';
55

66
describe('Service: <%= classifiedModuleName %>', () => {
77
beforeEach(() => {
8-
addProviders([<%= classifiedModuleName %>Service]);
8+
TestBed.configureTestingModule({
9+
providers: [<%= classifiedModuleName %>Service]
10+
});
911
});
1012

11-
it('should ...',
12-
inject([<%= classifiedModuleName %>Service],
13-
(service: <%= classifiedModuleName %>Service) => {
14-
expect(service).toBeTruthy();
15-
}));
13+
it('should ...', inject([<%= classifiedModuleName %>Service], (service: <%= classifiedModuleName %>Service) => {
14+
expect(service).toBeTruthy();
15+
}));
1616
});

0 commit comments

Comments
 (0)