@@ -31,33 +31,54 @@ describe('Chip Remove', () => {
31
31
32
32
describe ( 'basic behavior' , ( ) => {
33
33
it ( 'should applies the `mat-chip-remove` CSS class' , ( ) => {
34
- let hrefElement = chipNativeElement . querySelector ( 'a ' ) ! ;
34
+ let buttonElement = chipNativeElement . querySelector ( 'button ' ) ! ;
35
35
36
- expect ( hrefElement . classList ) . toContain ( 'mat-chip-remove' ) ;
36
+ expect ( buttonElement . classList ) . toContain ( 'mat-chip-remove' ) ;
37
37
} ) ;
38
38
39
39
it ( 'should emits (removed) on click' , ( ) => {
40
- let hrefElement = chipNativeElement . querySelector ( 'a ' ) ! ;
40
+ let buttonElement = chipNativeElement . querySelector ( 'button ' ) ! ;
41
41
42
42
testChip . removable = true ;
43
43
fixture . detectChanges ( ) ;
44
44
45
45
spyOn ( testChip , 'didRemove' ) ;
46
46
47
- hrefElement . click ( ) ;
47
+ buttonElement . click ( ) ;
48
+ fixture . detectChanges ( ) ;
48
49
49
50
expect ( testChip . didRemove ) . toHaveBeenCalled ( ) ;
50
51
} ) ;
52
+
53
+ it ( 'should not remove if parent chip is disabled' , ( ) => {
54
+ let buttonElement = chipNativeElement . querySelector ( 'button' ) ! ;
55
+
56
+ testChip . disabled = true ;
57
+ testChip . removable = true ;
58
+ fixture . detectChanges ( ) ;
59
+
60
+ spyOn ( testChip , 'didRemove' ) ;
61
+
62
+ buttonElement . click ( ) ;
63
+ fixture . detectChanges ( ) ;
64
+
65
+ expect ( testChip . didRemove ) . not . toHaveBeenCalled ( ) ;
66
+ } ) ;
67
+
51
68
} ) ;
52
69
} ) ;
53
70
54
71
@Component ( {
55
72
template : `
56
- <mat-chip [removable]="removable" (removed)="didRemove()"><a matChipRemove></a></mat-chip>
73
+ <mat-chip
74
+ [removable]="removable"
75
+ [disabled]="disabled"
76
+ (removed)="didRemove()"><button matChipRemove></button></mat-chip>
57
77
`
58
78
} )
59
79
class TestChip {
60
80
removable : boolean ;
81
+ disabled = false ;
61
82
62
83
didRemove ( ) { }
63
84
}
0 commit comments