-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathdomtesting.component.spec.ts
54 lines (43 loc) · 1.72 KB
/
domtesting.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
/* tslint:disable:no-unused-variable */
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DomTestingComponent } from './domtesting.component';
describe('DomTestingComponent', () => {
let component: DomTestingComponent;
let fixture: ComponentFixture<DomTestingComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DomTestingComponent]
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(DomTestingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should not have the DOM element if boolean is set to false', () => {
const containerElement = fixture.debugElement.query(By.css('.container'));
expect(containerElement).toBeNull();
});
it('should have the DOM element if boolean is set to true', () => {
component.isVisible = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
const containerElement = fixture.debugElement.query(By.css('.container'));
expect(containerElement).not.toBeNull();
});
});
it('clicking the button should toggle visiblity', async(() => {
const button = fixture.debugElement.query(By.css('button'));
expect(fixture.debugElement.query(By.css('.container'))).toBeNull();
button.triggerEventHandler('click', <Event>{});
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('.container'))).not.toBeNull();
button.triggerEventHandler('click', <Event>{});
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('.container'))).toBeNull();
}));
});