Skip to content

Commit a7fd926

Browse files
committed
Adds tests for active class
1 parent a6ed386 commit a7fd926

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/unit/Sticky-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ describe('Sticky', function () {
137137
// Scroll down to 10px, and Sticky should fix
138138
window.scrollTo(0, 10);
139139
shouldBeFixedAt(inner, 0);
140+
expect(outer.className).to.contain('active');
140141

141142
// Scroll up to 0px, and Sticky should reset
142143
window.scrollTo(0, 0);
143144
shouldBeReset(inner);
145+
expect(outer.className).to.not.contain('active');
144146
});
145147

146148
it('should work as expected (long Sticky)', function () {
@@ -158,26 +160,32 @@ describe('Sticky', function () {
158160
// Scroll down to 10px, and Sticky should stay as it was
159161
window.scrollTo(0, 10);
160162
shouldBeReleasedAt(inner, 0);
163+
expect(outer.className).to.not.contain('active');
161164

162165
// Scroll down to 1500px, and Sticky should fix to the bottom
163166
window.scrollTo(0, 1500);
164167
shouldBeFixedAt(inner, -432);
168+
expect(outer.className).to.contain('active');
165169

166170
// Scroll up to 1300px, and Sticky should release
167171
window.scrollTo(0, 1300);
168172
shouldBeReleasedAt(inner, 1068);
173+
expect(outer.className).to.not.contain('active');
169174

170175
// Scroll down to 1350px, and Sticky should release as it was
171176
window.scrollTo(0, 1350);
172177
shouldBeReleasedAt(inner, 1068);
178+
expect(outer.className).to.not.contain('active');
173179

174180
// Scroll up to 10px, and Sticky should fix
175181
window.scrollTo(0, 10);
176182
shouldBeFixedAt(inner, 0);
183+
expect(outer.className).to.contain('active');
177184

178185
// Scroll down to 20px, and Sticky should release
179186
window.scrollTo(0, 20);
180187
shouldBeReleasedAt(inner, 10);
188+
expect(outer.className).to.not.contain('active');
181189
});
182190

183191
it('should work as expected with original postion 20px from top (short Sticky)', function () {
@@ -195,10 +203,12 @@ describe('Sticky', function () {
195203
// Scroll down to 10px, and Sticky should stay
196204
window.scrollTo(0, 10);
197205
shouldBeReset(inner);
206+
expect(outer.className).to.not.contain('active');
198207

199208
// Scroll down to 50px, and Sticky should fix
200209
window.scrollTo(0, 50);
201210
shouldBeFixedAt(inner, 0);
211+
expect(outer.className).to.contain('active');
202212
});
203213

204214
it('should work as expected with original top 20px and 400px bottom boundary (short Sticky)', function () {
@@ -218,14 +228,17 @@ describe('Sticky', function () {
218228
// Scroll down to 10px, and Sticky should stay
219229
window.scrollTo(0, 10);
220230
shouldBeReset(inner);
231+
expect(outer.className).to.not.contain('active');
221232

222233
// Scroll down to 50px, and Sticky should fix
223234
window.scrollTo(0, 50);
224235
shouldBeFixedAt(inner, 0);
236+
expect(outer.className).to.contain('active');
225237

226238
// Scroll down to 150px, and Sticky should release
227239
window.scrollTo(0, 150);
228240
shouldBeReleasedAt(inner, 80);
241+
expect(outer.className).to.not.contain('active');
229242
});
230243

231244
it('should not be sticky if bottom boundary is shorter then its height (short Sticky)', function () {
@@ -244,11 +257,13 @@ describe('Sticky', function () {
244257
// Scroll down to 10px, and Sticky should stay
245258
window.scrollTo(0, 10);
246259
shouldBeReset(inner);
260+
expect(outer.className).to.not.contain('active');
247261

248262
// Micic status was not 0 (STATUS_ORIGINAL), scroll down to 20px, and Sticky should stay
249263
sticky.state.status = 2; // STATUS_FIXED;
250264
window.scrollTo(0, 20);
251265
shouldBeReset(inner);
266+
expect(outer.className).to.not.contain('active');
252267
});
253268

254269
it('should work as expected with selector bottom boundary (short Sticky)', function () {
@@ -268,14 +283,17 @@ describe('Sticky', function () {
268283
// Scroll down to 10px, and Sticky should fix
269284
window.scrollTo(0, 10);
270285
shouldBeFixedAt(inner, 20);
286+
expect(outer.className).to.contain('active');
271287

272288
// Scroll down to 50px, and Sticky should fix
273289
window.scrollTo(0, 50);
274290
shouldBeFixedAt(inner, 20);
291+
expect(outer.className).to.contain('active');
275292

276293
// Scroll down to 150px, and Sticky should release
277294
window.scrollTo(0, 150);
278295
shouldBeReleasedAt(inner, 100);
296+
expect(outer.className).to.not.contain('active');
279297
});
280298

281299
it('should stick to the top when window resizes larger then Sticky (long Sticky)', function () {
@@ -293,8 +311,10 @@ describe('Sticky', function () {
293311
// Scroll down to 10px, and Sticky should fix
294312
window.scrollTo(0, 10);
295313
shouldBeReleasedAt(inner, 0);
314+
expect(outer.className).to.not.contain('active');
296315

297316
window.resizeTo(0, 900);
298317
shouldBeFixedAt(inner, 0);
318+
expect(outer.className).to.contain('active');
299319
});
300320
});

0 commit comments

Comments
 (0)