1
1
import { Component } from '@angular/core' ;
2
- import { async , TestBed , ComponentFixture } from '@angular/core/testing' ;
2
+ import { async , TestBed } from '@angular/core/testing' ;
3
3
import { ObserveContentModule } from './observe-content' ;
4
4
5
5
/**
@@ -11,11 +11,7 @@ describe('Observe content', () => {
11
11
beforeEach ( async ( ( ) => {
12
12
TestBed . configureTestingModule ( {
13
13
imports : [ ObserveContentModule ] ,
14
- declarations : [
15
- ComponentWithTextContent ,
16
- ComponentWithChildTextContent ,
17
- ComponentWithDebouncedListener
18
- ] ,
14
+ declarations : [ ComponentWithTextContent , ComponentWithChildTextContent ] ,
19
15
} ) ;
20
16
21
17
TestBed . compileComponents ( ) ;
@@ -56,49 +52,6 @@ describe('Observe content', () => {
56
52
fixture . detectChanges ( ) ;
57
53
} ) ;
58
54
} ) ;
59
-
60
- // Note that these tests need to use real timeouts, instead of fakeAsync, because Angular doens't
61
- // mock out the MutationObserver, in addition to it being async. Perhaps we should find a way to
62
- // stub the MutationObserver for tests?
63
- describe ( 'debounced' , ( ) => {
64
- let fixture : ComponentFixture < ComponentWithDebouncedListener > ;
65
- let instance : ComponentWithDebouncedListener ;
66
-
67
- const setText = ( text : string , delay : number ) => {
68
- setTimeout ( ( ) => {
69
- instance . text = text ;
70
- fixture . detectChanges ( ) ;
71
- } , delay ) ;
72
- } ;
73
-
74
- beforeEach ( ( ) => {
75
- fixture = TestBed . createComponent ( ComponentWithDebouncedListener ) ;
76
- instance = fixture . componentInstance ;
77
- fixture . detectChanges ( ) ;
78
- } ) ;
79
-
80
- it ( 'should debounce the content changes' , ( done : any ) => {
81
- setText ( 'a' , 5 ) ;
82
- setText ( 'b' , 10 ) ;
83
- setText ( 'c' , 15 ) ;
84
-
85
- setTimeout ( ( ) => {
86
- expect ( instance . spy ) . toHaveBeenCalledTimes ( 1 ) ;
87
- done ( ) ;
88
- } , 50 ) ;
89
- } ) ;
90
-
91
- it ( 'should should keep track of all of the mutation records' , ( done : any ) => {
92
- setText ( 'a' , 5 ) ;
93
- setText ( 'b' , 10 ) ;
94
- setText ( 'c' , 15 ) ;
95
-
96
- setTimeout ( ( ) => {
97
- expect ( instance . spy . calls . mostRecent ( ) . args [ 0 ] . length ) . toBeGreaterThanOrEqual ( 1 ) ;
98
- done ( ) ;
99
- } , 50 ) ;
100
- } ) ;
101
- } ) ;
102
55
} ) ;
103
56
104
57
@@ -113,12 +66,3 @@ class ComponentWithChildTextContent {
113
66
text = '' ;
114
67
doSomething ( ) { }
115
68
}
116
-
117
- @Component ( {
118
- template : `<div (cdkObserveContent)="spy($event)" [debounce]="debounce">{{text}}</div>`
119
- } )
120
- class ComponentWithDebouncedListener {
121
- text = '' ;
122
- debounce = 15 ;
123
- spy = jasmine . createSpy ( 'MutationObserver callback' ) ;
124
- }
0 commit comments