-
Notifications
You must be signed in to change notification settings - Fork 125
/
badge.directive.spec.ts
53 lines (43 loc) · 1.76 KB
/
badge.directive.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
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
import { BadgeDirective } from './badge.directive';
@Component({
template: `
<span fd-badge>Fd-badge test</span>
`
})
export class TestComponent { }
describe('BadgeDirective', () => {
let component: TestComponent,
fixture: ComponentFixture<TestComponent>,
debugElement: DebugElement,
element: HTMLElement;
let directive, directiveInstance;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [BadgeDirective, TestComponent]
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
debugElement = fixture.debugElement;
element = debugElement.nativeElement;
fixture.detectChanges();
directive = debugElement.query(By.directive(BadgeDirective));
directiveInstance = directive.injector.get(BadgeDirective);
fixture = TestBed.createComponent(TestComponent);
spyOn(directiveInstance, '_setProperties').and.callThrough();
spyOn(directiveInstance, '_addClassToElement');
});
it('should create', () => {
expect(directive).toBeTruthy();
directiveInstance.status = 'someStatus';
directiveInstance.modifier = 'someModifier';
directiveInstance.ngOnInit();
expect(directiveInstance._setProperties).toHaveBeenCalled();
expect(directiveInstance._addClassToElement).toHaveBeenCalledWith('fd-badge--someStatus');
expect(directiveInstance._addClassToElement).toHaveBeenCalledWith('fd-badge--someModifier');
});
});