1
1
import { async , ComponentFixture , TestBed } from "@angular/core/testing" ;
2
+ import { By } from "@angular/platform-browser" ;
3
+ import { DebugElement } from "@angular/core" ;
2
4
3
5
import { TimeClockComponent } from "./time-clock.component" ;
6
+ import { ProjectListHoverComponent } from "../../shared/project-list-hover/project-list-hover.component" ;
4
7
5
8
describe ( "TimeClockComponent" , ( ) => {
6
9
let component : TimeClockComponent ;
7
10
let fixture : ComponentFixture < TimeClockComponent > ;
11
+ let de : DebugElement ;
8
12
9
13
function setup ( ) {
10
14
// tslint:disable-next-line: no-shadowed-variable
@@ -15,33 +19,49 @@ describe("TimeClockComponent", () => {
15
19
16
20
beforeEach ( async ( ( ) => {
17
21
TestBed . configureTestingModule ( {
18
- declarations : [ TimeClockComponent ]
22
+ declarations : [ TimeClockComponent , ProjectListHoverComponent ]
19
23
} ) . compileComponents ( ) ;
20
24
} ) ) ;
21
25
22
26
beforeEach ( ( ) => {
23
27
fixture = TestBed . createComponent ( TimeClockComponent ) ;
24
28
component = fixture . componentInstance ;
29
+ de = fixture . debugElement ;
25
30
fixture . detectChanges ( ) ;
26
31
} ) ;
27
32
28
33
it ( "should be created" , ( ) => {
29
34
expect ( component ) . toBeTruthy ( ) ;
30
35
} ) ;
31
36
32
- it ( ' should have p tag as \ 'time-clock works!\'' , async ( ( ) => {
37
+ it ( " should have p tag as 'time-clock works!'" , async ( ( ) => {
33
38
// tslint:disable-next-line: no-shadowed-variable
34
39
const { app, fixture } = setup ( ) ;
35
40
fixture . detectChanges ( ) ;
36
41
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!" ) ;
39
44
} ) ) ;
40
45
41
46
it ( "should set showfileds as true" , ( ) => {
42
47
const show = true ;
43
- component . showFields = show ;
44
48
component . setShowFields ( show ) ;
45
49
expect ( component . showFields ) . toBe ( true ) ;
46
50
} ) ;
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
+ } ) ;
47
67
} ) ;
0 commit comments