From a69aad2242a5be4ee21955d6132247b4781d410e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rn=20Zaefferer?= Date: Tue, 6 Feb 2007 11:55:44 +0000 Subject: [PATCH] Added equals helper for easier debugging of failed tests, soon to be used more often, see coreTest.js attr(String) for an example --- build/test/data/testrunner.js | 20 +++++++++++++++++++- src/jquery/coreTest.js | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/build/test/data/testrunner.js b/build/test/data/testrunner.js index e73fd67..899d670 100644 --- a/build/test/data/testrunner.js +++ b/build/test/data/testrunner.js @@ -218,4 +218,22 @@ function t(a,b,c) { */ function url(value) { return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); -} \ No newline at end of file +} + +/** + * Checks that the first two arguments are equal, with an optional message. + * Prints out both expected and actual values on failure. + * + * Prefered to ok( expected == actual, message ) + * + * @example equals( "Expected 2 characters.", v.formatMessage("Expected {0} characters.", 2) ); + * + * @param Object expected + * @param Object actual + * @param String message (optional) + */ +function equals(expected, actual, message) { + var result = expected == actual; + message = message || result ? "okay" : "failed"; + _config.Test.push( [ result, result ? message + ": " + expected : message + " expected: " + expected + " actual: " + actual ] ); +} diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js index f24a10b..11cb5fb 100644 --- a/src/jquery/coreTest.js +++ b/src/jquery/coreTest.js @@ -87,7 +87,7 @@ test("attr(String)", function() { ok( $('#name').attr('name') == "name", 'Check for name attribute' ); ok( $('#text1').attr('name') == "action", 'Check for name attribute' ); ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' ); - ok( $('#anchor2').attr('href') == "#2", 'Check for non-absolute href (an anchor)' ); + equals( "#2", $('#anchor2').attr('href'), 'Check for non-absolute href (an anchor)' ); stop(); $.get("data/dashboard.xml", function(xml) { ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" ); -- 1.7.10.4