@@ -19,6 +19,11 @@ describe('$anchorScroll', function() {
19
19
'</' + nodeName + '>' ,
20
20
jqElm = jqLite ( tmpl ) ,
21
21
elm = jqElm [ 0 ] ;
22
+ // Inline elements cause Firefox to report an unexpected value for
23
+ // `getBoundingClientRect().top` on some platforms (depending on the default font and
24
+ // line-height). Using inline-block elements prevents this.
25
+ // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1014738
26
+ elm . style . display = 'inline-block' ;
22
27
23
28
elmSpy [ identifier ] = spyOn ( elm , 'scrollIntoView' ) ;
24
29
jqLite ( $window . document . body ) . append ( jqElm ) ;
@@ -47,39 +52,6 @@ describe('$anchorScroll', function() {
47
52
} ;
48
53
}
49
54
50
- function expectScrollingTo ( identifierCountMap ) {
51
- var map = { } ;
52
- if ( isString ( identifierCountMap ) ) {
53
- map [ identifierCountMap ] = 1 ;
54
- } else if ( isArray ( identifierCountMap ) ) {
55
- forEach ( identifierCountMap , function ( identifier ) {
56
- map [ identifier ] = 1 ;
57
- } ) ;
58
- } else {
59
- map = identifierCountMap ;
60
- }
61
-
62
- return function ( $window ) {
63
- forEach ( elmSpy , function ( spy , id ) {
64
- var count = map [ id ] || 0 ;
65
- expect ( spy . callCount ) . toBe ( count ) ;
66
- } ) ;
67
- expect ( $window . scrollTo ) . not . toHaveBeenCalled ( ) ;
68
- } ;
69
- }
70
-
71
- function expectScrollingToTop ( $window ) {
72
- forEach ( elmSpy , function ( spy , id ) {
73
- expect ( spy ) . not . toHaveBeenCalled ( ) ;
74
- } ) ;
75
-
76
- expect ( $window . scrollTo ) . toHaveBeenCalledWith ( 0 , 0 ) ;
77
- }
78
-
79
- function expectNoScrolling ( ) {
80
- return expectScrollingTo ( NaN ) ;
81
- }
82
-
83
55
function createMockDocument ( initialReadyState ) {
84
56
var mockedDoc = { } ;
85
57
docSpies = { } ;
@@ -117,6 +89,59 @@ describe('$anchorScroll', function() {
117
89
return mockedDoc ;
118
90
}
119
91
92
+ function createMockWindow ( initialReadyState ) {
93
+ return function ( ) {
94
+ module ( function ( $provide ) {
95
+ elmSpy = { } ;
96
+ windowSpies = { } ;
97
+
98
+ $provide . value ( '$window' , {
99
+ scrollTo : ( windowSpies . scrollTo = jasmine . createSpy ( '$window.scrollTo' ) ) ,
100
+ scrollBy : ( windowSpies . scrollBy = jasmine . createSpy ( '$window.scrollBy' ) ) ,
101
+ document : createMockDocument ( initialReadyState ) ,
102
+ navigator : { } ,
103
+ pageYOffset : 0 ,
104
+ getComputedStyle : function ( elem ) {
105
+ return getComputedStyle ( elem ) ;
106
+ }
107
+ } ) ;
108
+ } ) ;
109
+ } ;
110
+ }
111
+
112
+ function expectNoScrolling ( ) {
113
+ return expectScrollingTo ( NaN ) ;
114
+ }
115
+
116
+ function expectScrollingTo ( identifierCountMap ) {
117
+ var map = { } ;
118
+ if ( isString ( identifierCountMap ) ) {
119
+ map [ identifierCountMap ] = 1 ;
120
+ } else if ( isArray ( identifierCountMap ) ) {
121
+ forEach ( identifierCountMap , function ( identifier ) {
122
+ map [ identifier ] = 1 ;
123
+ } ) ;
124
+ } else {
125
+ map = identifierCountMap ;
126
+ }
127
+
128
+ return function ( $window ) {
129
+ forEach ( elmSpy , function ( spy , id ) {
130
+ var count = map [ id ] || 0 ;
131
+ expect ( spy . callCount ) . toBe ( count ) ;
132
+ } ) ;
133
+ expect ( $window . scrollTo ) . not . toHaveBeenCalled ( ) ;
134
+ } ;
135
+ }
136
+
137
+ function expectScrollingToTop ( $window ) {
138
+ forEach ( elmSpy , function ( spy , id ) {
139
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
140
+ } ) ;
141
+
142
+ expect ( $window . scrollTo ) . toHaveBeenCalledWith ( 0 , 0 ) ;
143
+ }
144
+
120
145
function resetAllSpies ( ) {
121
146
function resetSpy ( spy ) {
122
147
spy . reset ( ) ;
@@ -140,28 +165,9 @@ describe('$anchorScroll', function() {
140
165
}
141
166
142
167
143
- function createMockWindow ( initialReadyState ) {
144
- return function ( ) {
145
- module ( function ( $provide ) {
146
- elmSpy = { } ;
147
- windowSpies = { } ;
148
-
149
- $provide . value ( '$window' , {
150
- scrollTo : ( windowSpies . scrollTo = jasmine . createSpy ( '$window.scrollTo' ) ) ,
151
- scrollBy : ( windowSpies . scrollBy = jasmine . createSpy ( '$window.scrollBy' ) ) ,
152
- document : createMockDocument ( initialReadyState ) ,
153
- navigator : { } ,
154
- pageYOffset : 0 ,
155
- getComputedStyle : function ( elem ) {
156
- return getComputedStyle ( elem ) ;
157
- }
158
- } ) ;
159
- } ) ;
160
- } ;
161
- }
162
-
163
- afterEach ( inject ( function ( $browser ) {
168
+ afterEach ( inject ( function ( $browser , $document ) {
164
169
expect ( $browser . deferredFns . length ) . toBe ( 0 ) ;
170
+ dealoc ( $document ) ;
165
171
} ) ) ;
166
172
167
173
@@ -311,10 +317,6 @@ describe('$anchorScroll', function() {
311
317
312
318
beforeEach ( createMockWindow ( ) ) ;
313
319
314
- afterEach ( inject ( function ( $document ) {
315
- dealoc ( $document ) ;
316
- } ) ) ;
317
-
318
320
319
321
it ( 'should scroll to element when hash change in hashbang mode' , function ( ) {
320
322
module ( initLocation ( { html5Mode : false , historyApi : true } ) ) ;
@@ -444,10 +446,6 @@ describe('$anchorScroll', function() {
444
446
beforeEach ( createMockWindow ( ) ) ;
445
447
beforeEach ( inject ( setupBodyForOffsetTesting ( ) ) ) ;
446
448
447
- afterEach ( inject ( function ( $document ) {
448
- dealoc ( $document ) ;
449
- } ) ) ;
450
-
451
449
452
450
describe ( 'when set as a fixed number' , function ( ) {
453
451
@@ -591,4 +589,3 @@ describe('$anchorScroll', function() {
591
589
} ) ;
592
590
} ) ;
593
591
} ) ;
594
-
0 commit comments