Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing some bugs with previous commit. Added object to JsUnitTest#ins…

…pect. Errors on hash equality now look like "Object: { test: test }" instead of "[Object Object]"

Changed test cases to flow with the inspect change.
  • Loading branch information...
commit 10e660edb65f535dc650ce5243040c955fc49566 1 parent 08bd8f2
@kristopher kristopher authored
Showing with 19 additions and 12 deletions.
  1. +6 −6 src/assertions.js
  2. +11 −4 src/common.js
  3. +2 −2 test/unit/test_case_test.html
View
12 src/assertions.js
@@ -32,22 +32,22 @@ JsUnitTest.Unit.Assertions = {
assertEnumEqual: function(expected, actual, message) {
message = this.buildMessage(message || 'assertEnumEqual', 'expected <?>, actual: <?>', expected, actual);
- this.assertBlock(message, JsUnitTest.areArraysEqual(expected, actual));
+ this.assertBlock(message, function() { return JsUnitTest.areArraysEqual(expected, actual) });
},
assertEnumNotEqual: function(expected, actual, message) {
message = this.buildMessage(message || 'assertEnumNotEqual', '<?> was the same as <?>', expected, actual);
- this.assert(message, JsUnitTest.areArraysNotEqual(expected_array, actual_array);
+ this.assertBlock(message, function() { return JsUnitTest.areArraysNotEqual(expected, actual) });
},
assertHashEqual: function(expected, actual, message) {
- message = this.buildMessage(message || 'assertHashEqual', 'expected <?>, actual: <?>', expected, actual);
- this.assert(message, JsUnitTest.areHashesEqual(expected_array, actual_array))
+ message = this.buildMessage(message || 'assertHashEqual', 'expected <?>, actual: <?>', JsUnitTest.inspect(expected), JsUnitTest.inspect(actual));
+ this.assertBlock(message, function() { return JsUnitTest.areHashesEqual(expected, actual) });
},
assertHashNotEqual: function(expected, actual, message) {
- message = this.buildMessage(message || 'assertHashNotEqual', '<?> was the same as <?>', expected, actual);
- this.assert(message, JsUnitTest.areHashesNotEqual(expected_array, actual_array));
+ message = this.buildMessage(message || 'assertHashNotEqual', '<?> was the same as <?>', JsUnitTest.inspect(expected), JsUnitTest.inspect(actual));
+ this.assertBlock(message, function() { return JsUnitTest.areHashesNotEqual(expected, actual) });
},
assertIdentical: function(expected, actual, message) {
View
15 src/common.js
@@ -13,6 +13,13 @@ var JsUnitTest = {
if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
return "'" + escapedString.replace(/'/g, '\\\'') + "'";
};
+ if ((typeof object == 'object') && (object.constructor == Object)) { // its probably an object.
+ var keys_values = new Array(), prefix = 'Object: { ';
+ for (property in object) {
+ keys_values.push(property + ': ' + object[property]);
+ }
+ return (prefix + keys_values.join(', ') + ' }');
+ }
return String(object);
} catch (e) {
if (e instanceof RangeError) return '...';
@@ -74,18 +81,18 @@ var JsUnitTest = {
return false;
},
- areArraysNotEqual: function(expected_array, actual_array) {
- return !this.areArraysEqual(expected_array, actual_array);
+ areArraysNotEqual: function(expected, actual) {
+ return !this.areArraysEqual(expected, actual);
},
areHashesEqual: function(expected, actual) {
var expected_array = JsUnitTest.hashToSortedArray(expected);
var actual_array = JsUnitTest.hashToSortedArray(actual);
- this.areArraysEqual(expected_array, actual_array);
+ return this.areArraysEqual(expected_array, actual_array);
},
areHashesNotEqual: function(expected, actual) {
- !this.areHashesNotEqual(expected_acutal);
+ return !this.areHashesEqual(expected, actual);
},
hashToSortedArray: function(hash) {
View
4 test/unit/test_case_test.html
@@ -86,7 +86,7 @@
testcase.error({name: "name", message: "An Error"});
assertEqual(0, testcase.assertions, "Assertions");
assertEqual(1, testcase.errors, "Errors");
- assertEqual("name: An Error([object Object])", testcase.messages[0], 'Should be equal');
+ assertEqual("name: An Error(Object: { name: name, message: An Error })", testcase.messages[0], 'Should be equal');
assertEqual('error', testcase.status(), 'Should be equal');
}},
@@ -94,4 +94,4 @@
// ]]>
</script>
</body>
-</html>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.