Created
November 10, 2013 21:55
-
-
Save berzniz/7404486 to your computer and use it in GitHub Desktop.
Blog post here: http://berzniz.com/post/66612637094/javascript-in-line-unit-tests Based on a comment to http://sergimansilla.com/blog/extending-js-inline-unit-tests/
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
var inline_test = function(func, inputs, expected_outputs) { | |
for (var i in inputs) { | |
var input = inputs[i]; | |
var expected = expected_outputs[i]; | |
var result = func(input); | |
if (result != expected) { | |
console.log('Test failed! Expected', expected, 'but got', result); | |
// Or throw an error... | |
} | |
} | |
return func; | |
}; | |
var square = inline_test(function square(n) { | |
return n * n; | |
}, [2, 4, 8, 16], [4, 16, 64, 99999]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment