forked from juristr/angular-testing-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
async-stream.component.spec.ts
54 lines (45 loc) · 1.46 KB
/
async-stream.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { tick } from '@angular/core/testing';
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { Component, Output, EventEmitter } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
@Component({
selector: 'test',
template: `
<div>{{ personName | async }}</div>
`
})
class AsyncComponent {
personName: Observable<string>;
}
describe('Async Compnent', () => {
let component: AsyncComponent;
let fixture: ComponentFixture<AsyncComponent>;
beforeEach(
async(() => {
TestBed.configureTestingModule({
declarations: [AsyncComponent]
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(AsyncComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should correctly visualize the emitted values from the stream', () => {
let stream = new Subject<string>();
component.personName = stream.asObservable();
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('div')).nativeElement.innerHTML).toBe('');
stream.next('Hi');
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('div')).nativeElement.innerHTML).toBe('Hi');
});
});