diff --git a/.jshintrc b/.jshintrc
index e6ef7cb..78aa4af 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -5,12 +5,8 @@
"strict": true,
"undef": true,
"unused": true,
- "predef": {
+ "globals": {
"imagesLoaded": false,
- "test": false,
- "ok": false,
- "equal": false,
- "start": false,
- "stop": false
+ "QUnit": false
}
}
diff --git a/test/append.js b/test/append.js
index b9d2d2b..b12d808 100644
--- a/test/append.js
+++ b/test/append.js
@@ -1,4 +1,6 @@
-test( 'append', function() {
+QUnit.test( 'append', function( assert ) {
+ 'use strict';
+
var imgUrls = [
'http://i.imgur.com/bwy74ok.jpg',
'http://i.imgur.com/bAZWoqx.jpg',
@@ -18,11 +20,11 @@ test( 'append', function() {
var elem = document.querySelector('#append');
elem.appendChild( fragment );
+ var done = assert.async();
- stop();
imagesLoaded( elem, { debug: true } ).on( 'always', function() {
- ok( 'appended images loaded' );
- start();
+ assert.ok( 'appended images loaded' );
+ done();
});
});
diff --git a/test/basics.js b/test/basics.js
index 5e9ed84..6c502a7 100644
--- a/test/basics.js
+++ b/test/basics.js
@@ -1,46 +1,28 @@
-test( 'basics', function() {
+QUnit.test( 'basics', function( assert ) {
'use strict';
var elem = document.querySelector('#basics');
var images = elem.querySelectorAll('img');
- var isCallbacked, isDone, isAlways, isAllProgressed;
- // stop();
+ var done = assert.async( 3 + images.length );
+
var imgLoader = new imagesLoaded( elem, function( obj ) {
- ok( true, 'callback function triggered' );
- equal( imgLoader, obj, 'callback argument and instance match' );
- isCallbacked = true;
- checkReady();
+ assert.ok( true, 'callback function triggered' );
+ assert.equal( imgLoader, obj, 'callback argument and instance match' );
+ done();
});
imgLoader.on( 'done', function() {
- ok( true, 'done event triggered' );
- isDone = true;
- checkReady();
+ assert.ok( true, 'done event triggered' );
+ done();
});
imgLoader.on( 'always', function() {
- ok( true, 'always event triggered' );
- isAlways = true;
- checkReady();
+ assert.ok( true, 'always event triggered' );
+ done();
});
- var progressCount = 0;
imgLoader.on( 'progress', function( loader, image ) {
- ok( image.isLoaded, 'image is loaded');
- progressCount++;
- if ( progressCount >= images.length ) {
- equal( progressCount, images.length, 'progressed right amount of times' );
- isAllProgressed = true;
- checkReady();
- }
+ assert.ok( image.isLoaded, 'image is loaded');
+ done();
});
- stop();
-
- function checkReady() {
- if ( isCallbacked && isDone && isAlways && isAllProgressed ) {
- start();
- }
- }
-
-
});
diff --git a/test/data-uri.js b/test/data-uri.js
index c52ae12..80da030 100644
--- a/test/data-uri.js
+++ b/test/data-uri.js
@@ -1,10 +1,10 @@
-test( 'data-uri', function() {
+QUnit.test( 'data-uri', function( assert ) {
'use strict';
- stop();
+ var done = assert.async();
imagesLoaded('#data-uri', { debug: true }).on( 'done', function( obj ) {
- ok( true, 'data-uri images loaded' );
- equal( obj.images.length, 2, 'instance has 2 images' );
- start();
+ assert.ok( true, 'data-uri images loaded' );
+ assert.equal( obj.images.length, 2, 'instance has 2 images' );
+ done();
});
});
diff --git a/test/jquery-fail.js b/test/jquery-fail.js
index 6f359a5..b2180f6 100644
--- a/test/jquery-fail.js
+++ b/test/jquery-fail.js
@@ -1,44 +1,29 @@
-test( 'jquery fail', function() {
+QUnit.test( 'jquery fail', function( assert ) {
'use strict';
var $ = window.jQuery;
- var isCallbacked, isFailed, isAlways, isAllProgressed;
- var progressCount = 0;
var $images = $('#jquery-fail img');
- stop();
+ var done = assert.async( 3 + $images.length );
$('#jquery-fail').imagesLoaded( function( instance ) {
- ok( true, 'callback triggered' );
- ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
- isCallbacked = true;
- checkReady();
+ assert.ok( true, 'callback triggered' );
+ assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
+ done();
})
.fail( function( instance ) {
- ok( true, 'done triggered' );
- ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
- isFailed = true;
- checkReady();
+ assert.ok( true, 'fail triggered' );
+ assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
+ done();
})
.always( function( instance ) {
- ok( true, 'always triggered' );
- ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
- isAlways = true;
- checkReady();
+ assert.ok( true, 'always triggered' );
+ assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
+ done();
})
- .progress( function() {
- progressCount++;
- if ( progressCount >= $images.length ) {
- equal( progressCount, $images.length, 'progressed iterations matches images length' );
- isAllProgressed = true;
- checkReady();
- }
+ .progress( function(/* instance, image */) {
+ assert.ok( true, 'progress trigged');
+ done();
});
- function checkReady() {
- if ( isCallbacked && isFailed && isAlways && isAllProgressed ) {
- start();
- }
- }
-
-});
+ });
diff --git a/test/jquery-success.js b/test/jquery-success.js
index 5a1089a..f166210 100644
--- a/test/jquery-success.js
+++ b/test/jquery-success.js
@@ -1,44 +1,28 @@
-test( 'jquery success', function() {
+QUnit.test( 'jquery success', function( assert ) {
'use strict';
var $ = window.jQuery;
- var isCallbacked, isDone, isAlways, isAllProgressed;
- var progressCount = 0;
- stop();
+ var done = assert.async( 6 );
$('#jquery-success').imagesLoaded( function( instance ) {
- ok( true, 'callback triggered' );
- ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
- isCallbacked = true;
- checkReady();
+ assert.ok( true, 'callback triggered' );
+ assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
+ done();
})
.done( function( instance ) {
- ok( true, 'done triggered' );
- ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
- isDone = true;
- checkReady();
+ assert.ok( true, 'done triggered' );
+ assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
+ done();
})
.always( function( instance ) {
- ok( true, 'always triggered' );
- ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
- isAlways = true;
- checkReady();
+ assert.ok( true, 'always triggered' );
+ assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' );
+ done();
})
.progress( function( instance, image ) {
- ok( image.isLoaded, 'image is loaded');
- progressCount++;
- if ( progressCount >= 3 ) {
- equal( progressCount, 3, 'progressed 3 times' );
- isAllProgressed = true;
- checkReady();
- }
+ assert.ok( image.isLoaded, 'progress trigged, image is loaded');
+ done();
});
- function checkReady() {
- if ( isCallbacked && isDone && isAlways && isAllProgressed ) {
- start();
- }
- }
-
});
diff --git a/test/local-files.js b/test/local-files.js
index 67562c3..61da6ae 100644
--- a/test/local-files.js
+++ b/test/local-files.js
@@ -1,49 +1,31 @@
-test( 'local files', function() {
-
+QUnit.test( 'local files', function( assert ) {
'use strict';
var elem = document.querySelector('#locals');
- var isCallbacked, isFailed, isAlways, isAllProgressed;
- // stop();
+ var done = assert.async( 6 );
+
var imgLoader = new imagesLoaded( elem, function( obj ) {
- ok( true, 'callback function triggered' );
- equal( imgLoader, obj, 'callback argument and instance match' );
- isCallbacked = true;
- checkReady();
+ assert.ok( true, 'callback function triggered' );
+ assert.equal( imgLoader, obj, 'callback argument and instance match' );
+ done();
});
imgLoader.on( 'fail', function() {
- ok( true, 'fail event triggered' );
- isFailed = true;
- checkReady();
+ assert.ok( true, 'fail event triggered' );
+ done();
});
imgLoader.on( 'always', function() {
- ok( true, 'always event triggered' );
- isAlways = true;
- checkReady();
+ assert.ok( true, 'always event triggered' );
+ done();
});
- var progressCount = 0;
imgLoader.on( 'progress', function( loader, image ) {
- ok( true, 'image progressed');
+ assert.ok( true, 'image progressed');
if ( image.img.src.indexOf('img/not-there.jpg') !== -1 ) {
- ok( !image.isLoaded, 'thunder cloud is not loaded' );
+ assert.ok( !image.isLoaded, 'thunder cloud is not loaded' );
} else {
- ok( image.isLoaded, 'image is loaded' );
- }
- progressCount++;
- if ( progressCount >= 3 ) {
- equal( progressCount, 3, 'progressed 3 times' );
- isAllProgressed = true;
- checkReady();
+ assert.ok( image.isLoaded, 'image is loaded' );
}
+ done();
});
- stop();
-
- function checkReady() {
- if ( isCallbacked && isFailed && isAlways && isAllProgressed ) {
- start();
- }
- }
-
});
diff --git a/test/no-images.js b/test/no-images.js
index 3bdf883..8412163 100644
--- a/test/no-images.js
+++ b/test/no-images.js
@@ -1,12 +1,11 @@
-test( 'no images', function() {
-
+QUnit.test( 'no images', function( assert ) {
'use strict';
var elem = document.querySelector('#no-images');
- stop();
+ var done = assert.async();
imagesLoaded( elem, function() {
- ok( true, 'triggered with no images' );
- start();
+ assert.ok( true, 'triggered with no images' );
+ done();
});
});
diff --git a/test/non-element.js b/test/non-element.js
index d350539..5e907cd 100644
--- a/test/non-element.js
+++ b/test/non-element.js
@@ -1,27 +1,24 @@
-test( 'dismiss non-element nodes', function() {
-
+QUnit.test( 'dismiss non-element nodes', function( assert ) {
'use strict';
var $ = window.jQuery;
- stop();
+ var done = assert.async( 2 );
+
$(' ')
.imagesLoaded(function() {
- ok( true, 'elements from jQuery string ok' );
- start();
- testFrag();
+ assert.ok( true, 'elements from jQuery string ok' );
+ done();
});
- function testFrag() {
- stop();
- var frag = document.createDocumentFragment();
- var img = new Image();
- img.src = 'http://lorempixel.com/403/303/';
- frag.appendChild( img );
- var imgLoad = imagesLoaded( frag, function() {
- ok( true, 'document fragment ok' );
- equal( imgLoad.images.length, 1, '1 image found' );
- start();
- });
- }
+ // test fragment
+ var frag = document.createDocumentFragment();
+ var img = new Image();
+ img.src = 'http://lorempixel.com/403/303/';
+ frag.appendChild( img );
+ var imgLoad = imagesLoaded( frag, function() {
+ assert.ok( true, 'document fragment ok' );
+ assert.equal( imgLoad.images.length, 1, '1 image found' );
+ done();
+ });
});
diff --git a/test/selector-string.js b/test/selector-string.js
index d777057..8c43c4b 100644
--- a/test/selector-string.js
+++ b/test/selector-string.js
@@ -1,11 +1,12 @@
-test( 'selector string', function() {
- stop();
+QUnit.test( 'selector string', function( assert ) {
+ 'use strict';
var images = document.querySelectorAll('#basics img');
+ var done = assert.async();
var imgLoad = imagesLoaded('#basics', { debug: true }).on( 'done', function( obj ) {
- ok( true, 'selector string worked' );
- ok( obj.images, 'argument has images' );
- equal( obj.images.length, images.length, 'images.length matches' );
- start();
+ assert.ok( true, 'selector string worked' );
+ assert.ok( obj.images, 'argument has images' );
+ assert.equal( obj.images.length, images.length, 'images.length matches' );
+ done();
});
- ok( imgLoad.options.debug, 'debug option set' );
+ assert.ok( imgLoad.options.debug, 'debug option set' );
});
diff --git a/test/single-element.js b/test/single-element.js
index f6110f6..42d7e48 100644
--- a/test/single-element.js
+++ b/test/single-element.js
@@ -1,10 +1,11 @@
-test( 'single element', function() {
+QUnit.test( 'single element', function( assert ) {
+ 'use strict';
var elem = document.querySelector('#mario-with-shell');
- stop();
+ var done = assert.async();
imagesLoaded( elem ).on( 'done', function( obj ) {
- ok( true, 'single element worked' );
- ok( obj.images, 'argument has images' );
- equal( obj.images.length, 1, 'images.length = 1' );
- start();
+ assert.ok( true, 'single element worked' );
+ assert.ok( obj.images, 'argument has images' );
+ assert.equal( obj.images.length, 1, 'images.length = 1' );
+ done();
});
});