@@ -41,32 +41,54 @@ describe('Scroll Dispatcher', () => {
41
41
42
42
it ( 'should notify through the directive and service that a scroll event occurred' ,
43
43
fakeAsync ( ( ) => {
44
- let hasDirectiveScrollNotified = false ;
45
44
// Listen for notifications from scroll directive
46
- let scrollable = fixture . componentInstance . scrollable ;
47
- scrollable . elementScrolled ( ) . subscribe ( ( ) => { hasDirectiveScrollNotified = true ; } ) ;
45
+ const scrollable = fixture . componentInstance . scrollable ;
46
+ const directiveSpy = jasmine . createSpy ( 'directive scroll callback' ) ;
47
+ scrollable . elementScrolled ( ) . subscribe ( directiveSpy ) ;
48
48
49
49
// Listen for notifications from scroll service with a throttle of 100ms
50
50
const throttleTime = 100 ;
51
- let hasServiceScrollNotified = false ;
52
- scroll . scrolled ( throttleTime , ( ) => { hasServiceScrollNotified = true ; } ) ;
51
+ const serviceSpy = jasmine . createSpy ( 'service scroll callback' ) ;
52
+ scroll . scrolled ( throttleTime , serviceSpy ) ;
53
53
54
54
// Emit a scroll event from the scrolling element in our component.
55
55
// This event should be picked up by the scrollable directive and notify.
56
56
// The notification should be picked up by the service.
57
57
dispatchFakeEvent ( fixture . componentInstance . scrollingElement . nativeElement , 'scroll' ) ;
58
58
59
59
// The scrollable directive should have notified the service immediately.
60
- expect ( hasDirectiveScrollNotified ) . toBe ( true ) ;
60
+ expect ( directiveSpy ) . toHaveBeenCalled ( ) ;
61
61
62
62
// Verify that the throttle is used, the service should wait for the throttle time until
63
63
// sending the notification.
64
- expect ( hasServiceScrollNotified ) . toBe ( false ) ;
64
+ expect ( serviceSpy ) . not . toHaveBeenCalled ( ) ;
65
65
66
66
// After the throttle time, the notification should be sent.
67
67
tick ( throttleTime ) ;
68
- expect ( hasServiceScrollNotified ) . toBe ( true ) ;
68
+ expect ( serviceSpy ) . toHaveBeenCalled ( ) ;
69
69
} ) ) ;
70
+
71
+ it ( 'should not execute the global events in the Angular zone' , ( ) => {
72
+ const spy = jasmine . createSpy ( 'zone unstable callback' ) ;
73
+ const subscription = fixture . ngZone . onUnstable . subscribe ( spy ) ;
74
+
75
+ scroll . scrolled ( 0 , ( ) => { } ) ;
76
+ dispatchFakeEvent ( document , 'scroll' ) ;
77
+ dispatchFakeEvent ( window , 'resize' ) ;
78
+
79
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
80
+ subscription . unsubscribe ( ) ;
81
+ } ) ;
82
+
83
+ it ( 'should not execute the scrollable events in the Angular zone' , ( ) => {
84
+ const spy = jasmine . createSpy ( 'zone unstable callback' ) ;
85
+ const subscription = fixture . ngZone . onUnstable . subscribe ( spy ) ;
86
+
87
+ dispatchFakeEvent ( fixture . componentInstance . scrollingElement . nativeElement , 'scroll' ) ;
88
+
89
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
90
+ subscription . unsubscribe ( ) ;
91
+ } ) ;
70
92
} ) ;
71
93
72
94
describe ( 'Nested scrollables' , ( ) => {
0 commit comments