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

Commit 69294a2

Browse files
Foxandxsswardbell
authored andcommitted
docs(testing): port to Angular v4 (#3524)
1 parent 2287304 commit 69294a2

7 files changed

+21
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function createComponent() {
141141
comp = fixture.componentInstance;
142142

143143
const injector = fixture.debugElement.injector;
144-
location = injector.get(Location);
144+
location = injector.get(Location) as SpyLocation;
145145
router = injector.get(Router);
146146
router.initialNavigation();
147147
spyOn(injector.get(TwainService), 'getQuote')

public/docs/_examples/testing/ts/src/app/bag/async-helper.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Angular async helper', () => {
3434

3535
// Use done. Cannot use setInterval with async or fakeAsync
3636
// See https://github.com/angular/angular/issues/10127
37-
it('should run async test with successful delayed Observable', done => {
37+
it('should run async test with successful delayed Observable', (done: any) => {
3838
const source = Observable.of(true).delay(10);
3939
source.subscribe(
4040
val => actuallyDone = true,

public/docs/_examples/testing/ts/src/app/bag/bag.no-testbed.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ describe('FancyService without the TestBed', () => {
1818
expect(service.getValue()).toBe('real value');
1919
});
2020

21-
it('#getAsyncValue should return async value', done => {
21+
it('#getAsyncValue should return async value', (done: DoneFn) => {
2222
service.getAsyncValue().then(value => {
2323
expect(value).toBe('async value');
2424
done();
2525
});
2626
});
2727

2828
// #docregion getTimeoutValue
29-
it('#getTimeoutValue should return timeout value', done => {
29+
it('#getTimeoutValue should return timeout value', (done: DoneFn) => {
3030
service = new FancyService();
3131
service.getTimeoutValue().then(value => {
3232
expect(value).toBe('timeout value');
@@ -35,7 +35,7 @@ describe('FancyService without the TestBed', () => {
3535
});
3636
// #enddocregion getTimeoutValue
3737

38-
it('#getObservableValue should return observable value', done => {
38+
it('#getObservableValue should return observable value', (done: DoneFn) => {
3939
service.getObservableValue().subscribe(value => {
4040
expect(value).toBe('observable value');
4141
done();

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('use inject helper in beforeEach', () => {
7373
}));
7474

7575
// Must use done. See https://github.com/angular/angular/issues/10127
76-
it('test should wait for FancyService.getObservableDelayValue', done => {
76+
it('test should wait for FancyService.getObservableDelayValue', (done: DoneFn) => {
7777
service.getObservableDelayValue().subscribe(value => {
7878
expect(value).toBe('observable delay value');
7979
done();
@@ -187,20 +187,21 @@ describe('TestBed Component Tests', () => {
187187
expect(selected).toHaveText(hero.name);
188188
});
189189

190-
it('can access the instance variable of an `*ngFor` row', () => {
190+
it('can access the instance variable of an `*ngFor` row component', () => {
191191
const fixture = TestBed.createComponent(IoParentComponent);
192192
const comp = fixture.componentInstance;
193+
const heroName = comp.heroes[0].name; // first hero's name
193194

194195
fixture.detectChanges();
195-
const heroEl = fixture.debugElement.query(By.css('.hero')); // first hero
196+
const ngForRow = fixture.debugElement.query(By.directive(IoComponent)); // first hero ngForRow
196197

197-
const ngForRow = heroEl.parent; // Angular's NgForRow wrapper element
198+
const hero = ngForRow.context['hero']; // the hero object passed into the row
199+
expect(hero.name).toBe(heroName, 'ngRow.context.hero');
198200

199-
// jasmine.any is instance-of-type test.
200-
expect(ngForRow.componentInstance).toEqual(jasmine.any(IoComponent), 'component is IoComp');
201-
202-
const hero = ngForRow.context['$implicit']; // the hero object
203-
expect(hero.name).toBe(comp.heroes[0].name, '1st hero\'s name');
201+
const rowComp = ngForRow.componentInstance;
202+
// jasmine.any is an "instance-of-type" test.
203+
expect(rowComp).toEqual(jasmine.any(IoComponent), 'component is IoComp');
204+
expect(rowComp.hero.name).toBe(heroName, 'component.hero');
204205
});
205206

206207

@@ -343,7 +344,7 @@ describe('TestBed Component Tests', () => {
343344
const childComp = el.componentInstance as BankAccountComponent;
344345
expect(childComp).toEqual(jasmine.any(BankAccountComponent));
345346

346-
expect(el.context).toBe(comp, 'context is the parent component');
347+
expect(el.context).toBe(childComp, 'context is the child component');
347348

348349
expect(el.attributes['account']).toBe(childComp.id, 'account attribute');
349350
expect(el.attributes['bank']).toBe(childComp.bank, 'bank attribute');
@@ -447,7 +448,7 @@ describe('TestBed Component Overrides:', () => {
447448
// `inject` uses TestBed's injector
448449
inject([FancyService], (s: FancyService) => testBedProvider = s)();
449450
tcProvider = fixture.debugElement.injector.get(FancyService);
450-
tpcProvider = fixture.debugElement.children[0].injector.get(FancyService);
451+
tpcProvider = fixture.debugElement.children[0].injector.get(FancyService) as FakeFancyService;
451452

452453
expect(testBedProvider).not.toBe(tcProvider, 'testBed/tc not same providers');
453454
expect(testBedProvider).not.toBe(tpcProvider, 'testBed/tpc not same providers');

public/docs/_examples/testing/ts/src/app/hero/hero-detail.component.no-testbed.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('HeroDetailComponent - no TestBed', () => {
1212
let hds: any;
1313
let router: any;
1414

15-
beforeEach( done => {
15+
beforeEach((done: any) => {
1616
expectedHero = new Hero(42, 'Bubba');
1717
activatedRoute = new ActivatedRouteStub();
1818
activatedRoute.testParams = { id: expectedHero.id };
@@ -45,7 +45,7 @@ describe('HeroDetailComponent - no TestBed', () => {
4545
expect(router.navigate.calls.any()).toBe(false, 'router.navigate not called yet');
4646
});
4747

48-
it('should navigate when click save resolves', done => {
48+
it('should navigate when click save resolves', (done: any) => {
4949
comp.save();
5050
// waits for async save to complete before navigating
5151
hds.saveHero.calls.first().returnValue

public/docs/_examples/testing/ts/src/app/hero/hero-detail.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function overrideSetup() {
9090
beforeEach( async(() => {
9191
createComponent();
9292
// get the component's injected HeroDetailServiceSpy
93-
hdsSpy = fixture.debugElement.injector.get(HeroDetailService);
93+
hdsSpy = fixture.debugElement.injector.get(HeroDetailService) as any;
9494
}));
9595

9696
it('should have called `getHero`', () => {

public/docs/_examples/testing/ts/src/app/shared/twain.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('TwainComponent', () => {
7878
// #enddocregion tests
7979

8080
// #docregion done-test
81-
it('should show quote after getQuote promise (done)', done => {
81+
it('should show quote after getQuote promise (done)', (done: any) => {
8282
fixture.detectChanges();
8383

8484
// get the spy promise and wait for it to resolve

0 commit comments

Comments
 (0)