-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.component.done.spec.ts
54 lines (50 loc) · 1.61 KB
/
app.component.done.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 {TestBed, waitForAsync} from '@angular/core/testing';
import {RouterTestingModule} from '@angular/router/testing';
import {AppComponent} from './app.component';
describe('AppComponent: done', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
AppComponent
],
}).compileComponents();
});
it('should create the app', (done) => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
done();
});
it('should show initialized component', (done) => {
const fixture = TestBed.createComponent(AppComponent);
const compiled = fixture.nativeElement;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const element = compiled.querySelector('#init');
expect(element).toBeTruthy();
expect(element.textContent).toContain('initialized');
done();
});
});
it('clicking button will call service', (done) => {
const fixture = TestBed.createComponent(AppComponent);
const compiled = fixture.nativeElement;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const button = compiled.querySelector('#button');
expect(button).toBeTruthy();
button.click();
fixture.whenStable().then(() => {
fixture.detectChanges();
const element = compiled.querySelector('#executed');
expect(element.textContent).toContain('executed');
done();
});
});
});
});