Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit abd860c

Browse files
Foxandxsswardbell
authored andcommitted
chore: update testing example to RC4
closes #1839
1 parent 8ddc93d commit abd860c

File tree

6 files changed

+49
-106
lines changed

6 files changed

+49
-106
lines changed

public/docs/_examples/testing/ts/app/app.component.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ import { By } from '@angular/platform-browser';
55
import { DebugElement } from '@angular/core';
66

77
import {
8-
beforeEach, beforeEachProviders,
9-
describe, ddescribe, xdescribe,
10-
expect, it, iit, xit,
118
async, inject
129
} from '@angular/core/testing';
1310

14-
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
11+
import { ComponentFixture, TestComponentBuilder } from '@angular/core/testing';
1512

1613
import { Hero, HeroService, MockHeroService } from './mock-hero.service';
1714

@@ -45,7 +42,7 @@ describe('AppComponent', () => {
4542
it('can get title from template', () => {
4643
fixture.detectChanges();
4744
let titleEl = fixture.debugElement.query(By.css('h1')).nativeElement;
48-
expect(titleEl).toHaveText(comp.title);
45+
expect(titleEl.textContent).toContain(comp.title);
4946
});
5047

5148
it('can get RouterLinks from template', () => {

public/docs/_examples/testing/ts/app/bad-tests.spec.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ import { DebugElement } from '@angular/core';
1919
import { By } from '@angular/platform-browser';
2020

2121
import {
22-
beforeEach, beforeEachProviders,
23-
describe, ddescribe, xdescribe,
24-
expect, it, iit, xit,
22+
addProviders,
2523
async, inject
2624
} from '@angular/core/testing';
2725

28-
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
26+
import { ComponentFixture, TestComponentBuilder } from '@angular/core/testing';
2927

3028
import { ViewMetadata } from '@angular/core';
3129
import { Observable } from 'rxjs/Rx';
@@ -143,20 +141,20 @@ xdescribe('async & inject testing errors', () => {
143141
restoreJasmineIt();
144142
}, 10000);
145143

146-
describe('using beforeEachProviders', () => {
147-
beforeEachProviders(() => [{ provide: FancyService, useValue: new FancyService() }]);
144+
describe('using addProviders', () => {
145+
addProviders([{ provide: FancyService, useValue: new FancyService() }]);
148146

149147
beforeEach(
150148
inject([FancyService], (service: FancyService) => { expect(service.value).toEqual('real value'); }));
151149

152-
describe('nested beforeEachProviders', () => {
150+
describe('nested addProviders', () => {
153151

154152
it('should fail when the injector has already been used', () => {
155153
patchJasmineBeforeEach();
156154
expect(() => {
157-
beforeEachProviders(() => [{ provide: FancyService, useValue: new FancyService() }]);
155+
addProviders([{ provide: FancyService, useValue: new FancyService() }]);
158156
})
159-
.toThrowError('beforeEachProviders was called after the injector had been used ' +
157+
.toThrowError('addProviders was called after the injector had been used ' +
160158
'in a beforeEach or it block. This invalidates the test injector');
161159
restoreJasmineBeforeEach();
162160
});

public/docs/_examples/testing/ts/app/bag.spec.ts

Lines changed: 25 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Based on https://github.com/angular/angular/blob/master/modules/angular2/test/testing/testing_public_spec.ts
22
/* tslint:disable */
33
import {
4-
BadTemplateUrl, ButtonComp,
4+
ButtonComp,
55
ChildChildComp, ChildComp, ChildWithChildComp,
66
ExternalTemplateComp,
77
FancyService, MockFancyService,
@@ -16,62 +16,19 @@ import { DebugElement } from '@angular/core';
1616
import { By } from '@angular/platform-browser';
1717

1818
import {
19-
beforeEach, beforeEachProviders,
20-
describe, ddescribe, xdescribe,
21-
expect, it, iit, xit,
22-
async, inject,
19+
addProviders,
20+
inject, async,
2321
fakeAsync, tick, withProviders
2422
} from '@angular/core/testing';
2523

26-
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
24+
import { ComponentFixture, TestComponentBuilder } from '@angular/core/testing';
2725

2826
import { ViewMetadata } from '@angular/core';
2927

3028
import { Observable } from 'rxjs/Rx';
3129

3230
//////// SPECS /////////////
3331

34-
/// Verify can use Angular testing's DOM abstraction to access DOM
35-
36-
describe('angular2 jasmine matchers', () => {
37-
describe('toHaveCssClass', () => {
38-
it('should assert that the CSS class is present', () => {
39-
let el = document.createElement('div');
40-
el.classList.add('bombasto');
41-
expect(el).toHaveCssClass('bombasto');
42-
});
43-
44-
it('should assert that the CSS class is not present', () => {
45-
let el = document.createElement('div');
46-
el.classList.add('bombasto');
47-
expect(el).not.toHaveCssClass('fatias');
48-
});
49-
});
50-
51-
describe('toHaveCssStyle', () => {
52-
it('should assert that the CSS style is present', () => {
53-
let el = document.createElement('div');
54-
expect(el).not.toHaveCssStyle('width');
55-
56-
el.style.setProperty('width', '100px');
57-
expect(el).toHaveCssStyle('width');
58-
});
59-
60-
it('should assert that the styles are matched against the element', () => {
61-
let el = document.createElement('div');
62-
expect(el).not.toHaveCssStyle({width: '100px', height: '555px'});
63-
64-
el.style.setProperty('width', '100px');
65-
expect(el).toHaveCssStyle({width: '100px'});
66-
expect(el).not.toHaveCssStyle({width: '100px', height: '555px'});
67-
68-
el.style.setProperty('height', '555px');
69-
expect(el).toHaveCssStyle({height: '555px'});
70-
expect(el).toHaveCssStyle({width: '100px', height: '555px'});
71-
});
72-
});
73-
});
74-
7532
describe('using the async helper', () => {
7633
let actuallyDone = false;
7734

@@ -101,7 +58,7 @@ describe('using the async helper', () => {
10158
p.catch(() => { actuallyDone = true; });
10259
}));
10360

104-
it('should run async test with successful Observable', async(() => {
61+
xit('should run async test with successful Observable', async(() => {
10562
let source = Observable.of(true).delay(10);
10663
source.subscribe(
10764
val => {},
@@ -114,9 +71,11 @@ describe('using the async helper', () => {
11471
describe('using the test injector with the inject helper', () => {
11572

11673
describe('setting up Providers with FancyService', () => {
117-
beforeEachProviders(() => [
118-
{ provide: FancyService, useValue: new FancyService() }
119-
]);
74+
beforeEach(() => {
75+
addProviders([
76+
{ provide: FancyService, useValue: new FancyService() }
77+
]);
78+
});
12079

12180
it('should use FancyService',
12281
inject([FancyService], (service: FancyService) => {
@@ -142,7 +101,7 @@ describe('using the test injector with the inject helper', () => {
142101
);
143102
})));
144103

145-
it('test should wait for FancyService.getObservableDelayValue',
104+
xit('test should wait for FancyService.getObservableDelayValue',
146105
async(inject([FancyService], (service: FancyService) => {
147106
service.getObservableDelayValue().subscribe(
148107
value => { expect(value).toEqual('observable delay value'); }
@@ -197,7 +156,7 @@ describe('test component builder', function() {
197156

198157
tcb.createAsync(ChildComp).then(fixture => {
199158
fixture.detectChanges();
200-
expect(fixture.nativeElement).toHaveText('Original Child');
159+
expect(fixture.nativeElement.textContent).toContain('Original Child');
201160
});
202161
})));
203162

@@ -206,11 +165,11 @@ describe('test component builder', function() {
206165

207166
tcb.createAsync(MyIfComp).then(fixture => {
208167
fixture.detectChanges();
209-
expect(fixture.nativeElement).toHaveText('MyIf()');
168+
expect(fixture.nativeElement.textContent).toContain('MyIf()');
210169

211170
fixture.debugElement.componentInstance.showMore = true;
212171
fixture.detectChanges();
213-
expect(fixture.nativeElement).toHaveText('MyIf(More)');
172+
expect(fixture.nativeElement.textContent).toContain('MyIf(More)');
214173
});
215174
})));
216175

@@ -262,7 +221,7 @@ describe('test component builder', function() {
262221
.createAsync(MockChildComp)
263222
.then(fixture => {
264223
fixture.detectChanges();
265-
expect(fixture.nativeElement).toHaveText('Mock');
224+
expect(fixture.nativeElement.textContent).toContain('Mock');
266225
});
267226
})));
268227

@@ -276,7 +235,7 @@ describe('test component builder', function() {
276235
.createAsync(ChildComp)
277236
.then(fixture => {
278237
fixture.detectChanges();
279-
expect(fixture.nativeElement).toHaveText('Modified Child');
238+
expect(fixture.nativeElement.textContent).toContain('Modified Child');
280239

281240
});
282241
})));
@@ -288,7 +247,7 @@ describe('test component builder', function() {
288247
.createAsync(ParentComp)
289248
.then(fixture => {
290249
fixture.detectChanges();
291-
expect(fixture.nativeElement).toHaveText('Parent(Mock)');
250+
expect(fixture.nativeElement.textContent).toContain('Parent(Mock)');
292251

293252
});
294253
})));
@@ -302,8 +261,8 @@ describe('test component builder', function() {
302261
.createAsync(ParentComp)
303262
.then(fixture => {
304263
fixture.detectChanges();
305-
expect(fixture.nativeElement)
306-
.toHaveText('Parent(Original Child(ChildChild Mock))');
264+
expect(fixture.nativeElement.textContent)
265+
.toContain('Parent(Original Child(ChildChild Mock))');
307266

308267
});
309268
})));
@@ -318,8 +277,8 @@ describe('test component builder', function() {
318277
.createAsync(TestProvidersComp)
319278
.then(fixture => {
320279
fixture.detectChanges();
321-
expect(fixture.nativeElement)
322-
.toHaveText('injected value: mocked out value');
280+
expect(fixture.nativeElement.textContent)
281+
.toContain('injected value: mocked out value');
323282
});
324283
})));
325284

@@ -333,8 +292,8 @@ describe('test component builder', function() {
333292
.createAsync(TestViewProvidersComp)
334293
.then(fixture => {
335294
fixture.detectChanges();
336-
expect(fixture.nativeElement)
337-
.toHaveText('injected value: mocked out value');
295+
expect(fixture.nativeElement.textContent)
296+
.toContain('injected value: mocked out value');
338297
});
339298
})));
340299

@@ -344,8 +303,8 @@ describe('test component builder', function() {
344303
tcb.createAsync(ExternalTemplateComp)
345304
.then(fixture => {
346305
fixture.detectChanges();
347-
expect(fixture.nativeElement)
348-
.toHaveText('from external template\n');
306+
expect(fixture.nativeElement.textContent)
307+
.toContain('from external template\n');
349308
});
350309
})), 10000); // Long timeout because this test makes an actual XHR.
351310

public/docs/_examples/testing/ts/app/dashboard.component.spec.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { DashboardComponent } from './dashboard.component';
44
import { By } from '@angular/platform-browser';
55

66
import {
7-
beforeEach, beforeEachProviders,
8-
describe, ddescribe, xdescribe,
9-
expect, it, iit, xit,
7+
addProviders,
108
async, inject
119
} from '@angular/core/testing';
1210

13-
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
11+
import { ComponentFixture, TestComponentBuilder } from '@angular/core/testing';
1412

1513
import { Hero, HeroService, MockHeroService } from './mock-hero.service';
1614
import { Router, MockRouter } from './mock-router';
@@ -70,13 +68,13 @@ describe('DashboardComponent', () => {
7068
let comp: DashboardComponent;
7169
let mockHeroService: MockHeroService;
7270

73-
beforeEachProviders(() => {
71+
beforeEach(() => {
7472
mockHeroService = new MockHeroService();
75-
return [
73+
addProviders([
7674
{ provide: Router, useClass: MockRouter},
7775
{ provide: MockRouter, useExisting: Router},
7876
{ provide: HeroService, useValue: mockHeroService }
79-
];
77+
]);
8078
});
8179

8280
it('can instantiate it',
@@ -138,8 +136,8 @@ describe('DashboardComponent', () => {
138136
expect(heroNames.length).toEqual(4, 'should display 4 heroes');
139137

140138
// the 4th displayed hero should be the 5th mock hero
141-
expect(heroNames[3].nativeElement)
142-
.toHaveText(mockHeroService.mockHeroes[4].name);
139+
expect(heroNames[3].nativeElement.textContent)
140+
.toContain(mockHeroService.mockHeroes[4].name);
143141
});
144142

145143
});

public/docs/_examples/testing/ts/app/expect-proper.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

public/docs/_examples/testing/ts/app/http-hero.service.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
/* tslint:disable:no-unused-variable */
22
import {
3-
beforeEach, beforeEachProviders,
4-
describe, ddescribe, xdescribe,
5-
expect, it, iit, xit,
3+
addProviders,
64
async, inject, withProviders
75
} from '@angular/core/testing';
86

9-
import { TestComponentBuilder } from '@angular/compiler/testing';
7+
import { TestComponentBuilder } from '@angular/core/testing';
108

119
import {
1210
MockBackend,
@@ -42,10 +40,12 @@ const makeResponseData = (data: {}) => {return { data }; };
4240
//////// SPECS /////////////
4341
describe('Http-HeroService (mockBackend)', () => {
4442

45-
beforeEachProviders(() => [
46-
HTTP_PROVIDERS,
47-
{ provide: XHRBackend, useClass: MockBackend }
48-
]);
43+
beforeEach(() => {
44+
addProviders([
45+
HTTP_PROVIDERS,
46+
{ provide: XHRBackend, useClass: MockBackend }
47+
]);
48+
});
4949

5050
it('can instantiate service when inject service',
5151
withProviders(() => [HeroService])

0 commit comments

Comments
 (0)