Skip to content

Commit

Permalink
close angular#3 - tests ok
Browse files Browse the repository at this point in the history
  • Loading branch information
vfedoriv committed May 16, 2018
1 parent c8b6b70 commit ace32ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
1 change: 0 additions & 1 deletion src/app/owners/owner-list/owner-list.component.html
Expand Up @@ -32,7 +32,6 @@ <h2>Owners</h2>
</thead>

<tbody>
<!-- <a routerLink="/owners/{{owner.id}}" routerLinkActive="active" -->
<tr *ngFor="let owner of owners">
<td class="ownerFullName"><a routerLink="/owners/{{owner.id}}" routerLinkActive="active"
(click)="onSelect(owner)">{{owner.firstName}} {{owner.lastName}}</a></td>
Expand Down
42 changes: 19 additions & 23 deletions src/app/owners/owner-list/owner-list.component.spec.ts
Expand Up @@ -24,21 +24,20 @@

import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {DebugElement, CUSTOM_ELEMENTS_SCHEMA, Component, NO_ERRORS_SCHEMA} from '@angular/core';
import {DebugElement, NO_ERRORS_SCHEMA} from '@angular/core';

import {OwnerListComponent} from './owner-list.component';
import {FormsModule} from '@angular/forms';
import {Router, RouterLink, ActivatedRoute} from '@angular/router';
import {ActivatedRoute} from '@angular/router';
import {OwnerService} from '../owner.service';
import Spy = jasmine.Spy;
import {Owner} from '../owner';
import {HttpModule} from '@angular/http';
import {Observable} from 'rxjs';
import {RouterTestingModule} from '@angular/router/testing';
import {APP_BASE_HREF, CommonModule} from '@angular/common';
import {WelcomeComponent} from '../../parts/welcome/welcome.component';
import {CommonModule} from '@angular/common';
import {PartsModule} from '../../parts/parts.module';
import {RouterStub, ActivatedRouteStub} from '../../testing/router-stubs';
import {ActivatedRouteStub} from '../../testing/router-stubs';
import {OwnerDetailComponent} from '../owner-detail/owner-detail.component';
import {OwnersModule} from '../owners.module';
import {DummyComponent} from '../../testing/dummy.component';
Expand Down Expand Up @@ -80,7 +79,6 @@ describe('OwnerListComponent', () => {
])],
providers: [
OwnerService,
{provide: Router, useClass: RouterStub},
{provide: ActivatedRoute, useClass: ActivatedRouteStub}
]
})
Expand Down Expand Up @@ -108,7 +106,6 @@ describe('OwnerListComponent', () => {
fixture = TestBed.createComponent(OwnerListComponent);
component = fixture.componentInstance;
ownerService = fixture.debugElement.injector.get(OwnerService);
// component.owners = testOwners;
spy = spyOn(ownerService, 'getOwners')
.and.returnValue(Observable.of(testOwners));

Expand All @@ -118,21 +115,20 @@ describe('OwnerListComponent', () => {
expect(component).toBeTruthy();
});

// TODO need fix - this part "routerLink="/owners/{{owner.id}}" routerLinkActive="active"" in html template cause test error
// it('should call ngOnInit() method', () => {
// fixture.detectChanges();
// expect(spy.calls.any()).toBe(true, 'getOwners called');
// });

// TODO need fix - this part "routerLink="/owners/{{owner.id}}" routerLinkActive="active"" in html template cause test error
// it(' should show full name after getOwners observable (async) ', async(() => {
// fixture.detectChanges();
// fixture.whenStable().then(() => { // wait for async getOwners
// fixture.detectChanges(); // update view with name
// de = fixture.debugElement.query(By.css('.ownerFullName'));
// el = de.nativeElement;
// expect(el.innerText).toBe((testOwner.firstName.toString() + ' ' + testOwner.lastName.toString()));
// });
// }));
it('should call ngOnInit() method', () => {
fixture.detectChanges();
expect(spy.calls.any()).toBe(true, 'getOwners called');
});


it(' should show full name after getOwners observable (async) ', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => { // wait for async getOwners
fixture.detectChanges(); // update view with name
de = fixture.debugElement.query(By.css('.ownerFullName'));
el = de.nativeElement;
expect(el.innerText).toBe((testOwner.firstName.toString() + ' ' + testOwner.lastName.toString()));
});
}));

});
7 changes: 0 additions & 7 deletions src/app/testing/router-stubs.ts
Expand Up @@ -77,10 +77,3 @@ export class ActivatedRouteStub {
return {params: this.testParams};
}
}


/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/

0 comments on commit ace32ea

Please sign in to comment.