forked from juristr/angular-testing-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic-css-classes.component.spec.ts
More file actions
58 lines (46 loc) · 1.57 KB
/
dynamic-css-classes.component.spec.ts
File metadata and controls
58 lines (46 loc) · 1.57 KB
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
55
56
57
58
/* 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, Input } from '@angular/core';
@Component({
selector: 'test',
template: `
<div [ngClass]="{ 'alert': isAlert, 'success': !isAlert }"></div>
`
})
class DynamicCssClassesComponent {
@Input() isAlert: boolean = false;
}
describe('DynamicCssClassesComponent', () => {
let component: DynamicCssClassesComponent;
let fixture: ComponentFixture<DynamicCssClassesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DynamicCssClassesComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DynamicCssClassesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should have the .alert class if isAlert is set to true', () => {
component.isAlert = true;
fixture.detectChanges();
let classes:any = fixture.debugElement.query(By.css('div')).classes;
expect(classes.alert).toBeTruthy();
expect(classes.success).toBeFalsy();
});
it('should have the .success class if isAlert is set to false', () => {
component.isAlert = false;
fixture.detectChanges();
let classes:any = fixture.debugElement.query(By.css('div')).classes;
expect(classes.success).toBeTruthy();
expect(classes.alert).toBeFalsy();
});
});