@@ -106,6 +106,12 @@ describe('$anchorScroll', function() {
106
106
107
107
describe ( 'watcher' , function ( ) {
108
108
109
+ function initAnchorScroll ( ) {
110
+ return function ( $rootScope , $anchorScroll ) {
111
+ $rootScope . $digest ( ) ;
112
+ } ;
113
+ }
114
+
109
115
function initLocation ( config ) {
110
116
return function ( $provide , $locationProvider ) {
111
117
$provide . value ( '$sniffer' , { history : config . historyApi } ) ;
@@ -135,6 +141,7 @@ describe('$anchorScroll', function() {
135
141
it ( 'should scroll to element when hash change in hashbang mode' , function ( ) {
136
142
module ( initLocation ( { html5Mode : false , historyApi : true } ) ) ;
137
143
inject (
144
+ initAnchorScroll ( ) ,
138
145
addElements ( 'id=some' ) ,
139
146
changeHashTo ( 'some' ) ,
140
147
expectScrollingTo ( 'id=some' )
@@ -145,16 +152,25 @@ describe('$anchorScroll', function() {
145
152
it ( 'should scroll to element when hash change in html5 mode with no history api' , function ( ) {
146
153
module ( initLocation ( { html5Mode : true , historyApi : false } ) ) ;
147
154
inject (
155
+ initAnchorScroll ( ) ,
148
156
addElements ( 'id=some' ) ,
149
157
changeHashTo ( 'some' ) ,
150
158
expectScrollingTo ( 'id=some' )
151
159
) ;
152
160
} ) ;
153
161
154
162
163
+ it ( 'should not scroll to the top if $anchorScroll is initializing and location hash is empty' ,
164
+ inject (
165
+ initAnchorScroll ( ) ,
166
+ expectNoScrolling ( ) )
167
+ ) ;
168
+
169
+
155
170
it ( 'should not scroll when element does not exist' , function ( ) {
156
171
module ( initLocation ( { html5Mode : false , historyApi : false } ) ) ;
157
172
inject (
173
+ initAnchorScroll ( ) ,
158
174
addElements ( 'id=some' ) ,
159
175
changeHashTo ( 'other' ) ,
160
176
expectNoScrolling ( )
@@ -165,6 +181,7 @@ describe('$anchorScroll', function() {
165
181
it ( 'should scroll when html5 mode with history api' , function ( ) {
166
182
module ( initLocation ( { html5Mode : true , historyApi : true } ) ) ;
167
183
inject (
184
+ initAnchorScroll ( ) ,
168
185
addElements ( 'id=some' ) ,
169
186
changeHashTo ( 'some' ) ,
170
187
expectScrollingTo ( 'id=some' )
0 commit comments