Created
March 1, 2014 01:01
-
-
Save DingoEatingFuzz/9283121 to your computer and use it in GitHub Desktop.
A QUnit assert to verify that an object or expression changes correctly over time (i.e., browser animation frames).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// watch assert | |
// expression: object reference or function | |
// values: an array of values | |
// message: QUnit assert message | |
// each value in values is compared against expression for | |
// a frame using requestAnimationFrame | |
QUnit.extend(QUnit.assert, { | |
watch: function(expression, values, message) { | |
var numSteps = values.length; | |
var steps = 0; | |
var val = expression instanceof Function | |
? function() { return expression(); } | |
: function() { return expression; } | |
; | |
step(); | |
function step() { | |
var a = val(); | |
var b = values[steps]; | |
QUnit.push(QUnit.equiv(a, b), a, b, message + ', step ' + steps); | |
++steps < numSteps | |
? requestAnimationFrame(step) | |
: start() | |
; | |
}; | |
} | |
}); | |
QUnit.asserts.watch(function() { return itemList.children().length; }, [ 300, 600, 900, 1000, 1000 ], | |
'rendering long lists takes multiple frames, but eventually finishes'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment