Skip to content

Commit a6d80a0

Browse files
committed
fix tests ('lazied' attribute is removed after image is displayed)
1 parent d18965c commit a6d80a0

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

test/lazyloadxt.html

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<!-- Load local lib and tests. -->
1212
<script src="../src/jquery.lazyloadxt.js"></script>
1313
<script src="../src/jquery.lazyloadxt.video.js"></script>
14+
<script>$.lazyLoadXT.autoInit = false;</script>
1415
<script src="lazyloadxt_test.js"></script>
1516
<!-- Removing access to jQuery and $. But it'll still be available as _$, if
1617
you REALLY want to mess around with jQuery in the console. REMEMBER WE

test/lazyloadxt_test.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
// This will run before each test in this module.
2828
setup: function () {
2929
this.elems = $('#qunit-fixture');
30+
$(window).lazyLoadXT();
3031
}
3132
});
3233

@@ -35,24 +36,25 @@
3536
strictEqual(this.elems.lazyLoadXT(), this.elems, 'should be chainable');
3637
});
3738

38-
asyncTest('is lazy loaded', function () {
39+
asyncTest('is lazy loading', function () {
3940
expect(5);
41+
var $img = $('img'),
42+
cntinit = $img.filter(function (index, el) {
43+
el = el || this;
44+
return $(el).data('lazied');
45+
}).length;
46+
ok($img.length > 0, 'images should be presented');
47+
ok(cntinit > 0, 'images should be initialized');
48+
ok(cntinit === $img.length, 'all images should be initialized');
4049
setTimeout(function () {
4150
var $img = $('img'),
42-
cntinit = $img.filter(function (index, el) {
43-
el = el || this;
44-
return $(el).data('lazied');
45-
}).length,
4651
cntnow = $img.filter(function (index, el) {
4752
el = el || this;
48-
return $(el).data('lazied') && ($(el).attr('src') === $(el).attr('data-src'));
53+
return ($(el).attr('src') === $(el).attr('data-src'));
4954
}).length;
50-
ok($img.length > 0, 'images should be presented');
51-
ok(cntinit > 0, 'images should be initialized');
52-
ok(cntinit === $img.length, 'all images should be initialized');
5355
ok(cntnow > 0, 'some images should be displayed');
5456
ok(cntnow < $img.length, 'not all images should be displayed');
5557
start();
56-
}, 300);
58+
}, 200);
5759
});
5860
}(window.jQLight || window.jQuery || window.Zepto || window.$));

0 commit comments

Comments
 (0)