@@ -12,81 +12,106 @@ describe('Waypoint Sticky Shortcut', function() {
1212 beforeEach ( function ( ) {
1313 loadFixtures ( 'sticky.html' )
1414 $sticky = $ ( '.sticky' )
15- handlerSpy = jasmine . createSpy ( 'on handler' )
16- waypoint = new Waypoint . Sticky ( {
17- element : $sticky [ 0 ] ,
18- handler : handlerSpy
19- } )
2015 } )
2116
22- afterEach ( function ( ) {
23- if ( waypoint ) {
24- waypoint . destroy ( )
25- }
26- $scroller . scrollTop ( 0 )
27- } )
17+ describe ( 'with default options' , function ( ) {
18+ beforeEach ( function ( ) {
19+ handlerSpy = jasmine . createSpy ( 'on handler' )
20+ waypoint = new Waypoint . Sticky ( {
21+ element : $sticky [ 0 ] ,
22+ handler : handlerSpy
23+ } )
24+ } )
2825
29- describe ( 'on init' , function ( ) {
3026 afterEach ( function ( ) {
31- waypoint . destroy ( )
27+ if ( waypoint ) {
28+ waypoint . destroy ( )
29+ }
30+ $scroller . scrollTop ( 0 )
3231 } )
3332
34- it ( 'returns an instance of the Waypoint.Sticky class' , function ( ) {
35- expect ( waypoint instanceof Waypoint . Sticky ) . toBeTruthy ( )
36- } )
33+ describe ( 'on init' , function ( ) {
34+ afterEach ( function ( ) {
35+ waypoint . destroy ( )
36+ } )
37+
38+ it ( 'returns an instance of the Waypoint.Sticky class' , function ( ) {
39+ expect ( waypoint instanceof Waypoint . Sticky ) . toBeTruthy ( )
40+ } )
41+
42+ it ( 'wraps the sticky element on init' , function ( ) {
43+ expect ( $sticky . parent ( ) ) . toHaveClass ( 'sticky-wrapper' )
44+ } )
45+
46+ describe ( 'when sticky element is scrolled to' , function ( ) {
47+ beforeEach ( function ( ) {
48+ runs ( function ( ) {
49+ $scroller . scrollTop ( $sticky . offset ( ) . top )
50+ } )
51+ waitsFor ( function ( ) {
52+ return $sticky . hasClass ( 'stuck' )
53+ } , 'stuck class to apply' )
54+ } )
55+
56+ it ( 'adds/removes stuck class' , function ( ) {
57+ runs ( function ( ) {
58+ $scroller . scrollTop ( $scroller . scrollTop ( ) - 1 )
59+ } )
60+ waitsFor ( function ( ) {
61+ return ! $sticky . hasClass ( 'stuck' )
62+ } )
63+ } )
64+
65+ it ( 'gives the wrapper the same height as the sticky element' , function ( ) {
66+ expect ( $sticky . parent ( ) . height ( ) ) . toEqual ( $sticky . outerHeight ( ) )
67+ } )
3768
38- it ( 'wraps the sticky element on init' , function ( ) {
39- expect ( $sticky . parent ( ) ) . toHaveClass ( 'sticky-wrapper' )
69+ it ( 'executes handler option after stuck class applied' , function ( ) {
70+ expect ( handlerSpy ) . toHaveBeenCalled ( )
71+ } )
72+ } )
4073 } )
4174
42- describe ( 'when sticky element is scrolled to ' , function ( ) {
75+ describe ( '#destroy ' , function ( ) {
4376 beforeEach ( function ( ) {
4477 runs ( function ( ) {
4578 $scroller . scrollTop ( $sticky . offset ( ) . top )
4679 } )
4780 waitsFor ( function ( ) {
48- return $sticky . hasClass ( 'stuck' )
49- } , 'stuck class to apply' )
50- } )
51-
52- it ( 'adds/removes stuck class' , function ( ) {
53- runs ( function ( ) {
54- $scroller . scrollTop ( $scroller . scrollTop ( ) - 1 )
81+ return handlerSpy . callCount
5582 } )
56- waitsFor ( function ( ) {
57- return ! $sticky . hasClass ( 'stuck' )
83+ runs ( function ( ) {
84+ waypoint . destroy ( )
5885 } )
5986 } )
6087
61- it ( 'gives the wrapper the same height as the sticky element' , function ( ) {
62- expect ( $sticky . parent ( ) . height ( ) ) . toEqual ( $sticky . outerHeight ( ) )
88+ it ( 'unwraps the sticky element' , function ( ) {
89+ expect ( $sticky . parent ( ) ) . not . toHaveClass ( 'sticky-wrapper' )
6390 } )
6491
65- it ( 'executes handler option after stuck class applied ' , function ( ) {
66- expect ( handlerSpy ) . toHaveBeenCalled ( )
92+ it ( 'removes the stuck class' , function ( ) {
93+ expect ( $sticky ) . not . toHaveClass ( 'stuck' )
6794 } )
6895 } )
6996 } )
7097
71- describe ( '#destroy ' , function ( ) {
98+ describe ( 'with wrapper false ' , function ( ) {
7299 beforeEach ( function ( ) {
73- runs ( function ( ) {
74- $scroller . scrollTop ( $sticky . offset ( ) . top )
75- } )
76- waitsFor ( function ( ) {
77- return handlerSpy . callCount
78- } )
79- runs ( function ( ) {
80- waypoint . destroy ( )
100+ waypoint = new Waypoint . Sticky ( {
101+ element : $sticky [ 0 ] ,
102+ handler : handlerSpy ,
103+ wrapper : false
81104 } )
82105 } )
83106
84- it ( 'unwraps the sticky element' , function ( ) {
107+ it ( 'does not wrap the sticky element' , function ( ) {
85108 expect ( $sticky . parent ( ) ) . not . toHaveClass ( 'sticky-wrapper' )
86109 } )
87110
88- it ( 'removes the stuck class' , function ( ) {
89- expect ( $sticky ) . not . toHaveClass ( 'stuck' )
111+ it ( 'does not unwrap on destroy' , function ( ) {
112+ var parent = waypoint . wrapper
113+ waypoint . destroy ( )
114+ expect ( parent ) . toBe ( waypoint . wrapper )
90115 } )
91116 } )
92117} )
0 commit comments