Skip to content

Commit 12a95bb

Browse files
committed
Add new tests
1 parent 747e09f commit 12a95bb

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
2+
import { By } from "@angular/platform-browser";
3+
import { DebugElement } from "@angular/core";
24

35
import { TimeClockComponent } from "./time-clock.component";
6+
import { ProjectListHoverComponent } from "../../shared/project-list-hover/project-list-hover.component";
47

58
describe("TimeClockComponent", () => {
69
let component: TimeClockComponent;
710
let fixture: ComponentFixture<TimeClockComponent>;
11+
let de: DebugElement;
812

913
function setup() {
1014
// tslint:disable-next-line: no-shadowed-variable
@@ -15,33 +19,49 @@ describe("TimeClockComponent", () => {
1519

1620
beforeEach(async(() => {
1721
TestBed.configureTestingModule({
18-
declarations: [TimeClockComponent]
22+
declarations: [TimeClockComponent, ProjectListHoverComponent]
1923
}).compileComponents();
2024
}));
2125

2226
beforeEach(() => {
2327
fixture = TestBed.createComponent(TimeClockComponent);
2428
component = fixture.componentInstance;
29+
de = fixture.debugElement;
2530
fixture.detectChanges();
2631
});
2732

2833
it("should be created", () => {
2934
expect(component).toBeTruthy();
3035
});
3136

32-
it('should have p tag as \'time-clock works!\'', async(() => {
37+
it("should have p tag as 'time-clock works!'", async(() => {
3338
// tslint:disable-next-line: no-shadowed-variable
3439
const { app, fixture } = setup();
3540
fixture.detectChanges();
3641
const compile = fixture.debugElement.nativeElement;
37-
const h1tag = compile.querySelector('p');
38-
expect(h1tag.textContent).toBe('time-clock works!');
42+
const h1tag = compile.querySelector("p");
43+
expect(h1tag.textContent).toBe("time-clock works!");
3944
}));
4045

4146
it("should set showfileds as true", () => {
4247
const show = true;
43-
component.showFields = show;
4448
component.setShowFields(show);
4549
expect(component.showFields).toBe(true);
4650
});
51+
52+
it('should be called the setShowFields event #1', () => {
53+
spyOn(component, 'setShowFields');
54+
const showFields = de.query(By.directive(ProjectListHoverComponent));
55+
const cmp = showFields.componentInstance;
56+
cmp.showFields.emit(true);
57+
expect(component.setShowFields).toHaveBeenCalledWith(true);
58+
});
59+
60+
it('should be called the setShowFields event #2', () => {
61+
spyOn(component, 'setShowFields');
62+
const showFields = de.query(By.directive(ProjectListHoverComponent));
63+
const li = showFields.query(By.css('li'));
64+
li.nativeElement.click();
65+
expect(component.setShowFields).toHaveBeenCalledWith(true);
66+
});
4767
});

0 commit comments

Comments
 (0)