Permalink
Browse files

Throw Errors so we're more likely to get backtraces

(Error was added in EcmaScript 1.3 in 1999, no compat issues)
  • Loading branch information...
1 parent 546e8f3 commit e4a494777d6098152ea0888f13c12bdd253b442a @bronson committed Oct 5, 2011
Showing with 10 additions and 10 deletions.
  1. +5 −5 test/valid.test.js
  2. +5 −5 test/validjson.test.js
View
@@ -11,16 +11,16 @@ Valid.assert = function assert(value, expected) {
if(expected !== actual) {
var exstr = (expected === undefined ? "success" : "'" + expected + "'");
var acstr = (actual === undefined ? "success" : "'" + actual + "'");
- throw value + ": expected " + exstr + " but got " + acstr;
+ throw Error(value + ": expected " + exstr + " but got " + acstr);
}
};
// first test the validation routines
-if(Valid.equal(4).check(4) !== undefined) throw "test() success needs to return undefined";
-if(Valid.equal(4).check(5) !== "is not equal to 4") throw "test() failure needs to return a string";
-if(Valid.equal(4).isValid(4) !== true) throw "check() success needs to return true";
-if(Valid.equal(4).isValid(5) !== false) throw "check() failure needs to return false";
+if(Valid.equal(4).check(4) !== undefined) throw Error("test() success needs to return undefined");
+if(Valid.equal(4).check(5) !== "is not equal to 4") throw Error("test() failure needs to return a string");
+if(Valid.equal(4).isValid(4) !== true) throw Error("check() success needs to return true");
+if(Valid.equal(4).isValid(5) !== false) throw Error("check() failure needs to return false");
Valid.assert("any value", "no validations!");
View
@@ -14,7 +14,7 @@ Valid.assert = function assert(value, expected) {
if(diffstr) {
var exstr = (expected === undefined ? "success" : JSON.stringify(expected));
var acstr = (actual === undefined ? "success" : JSON.stringify(actual));
- throw value + ":\n expected " + exstr + "\n but got " + acstr + "\n (" + diffstr + ")";
+ throw Error(value + ":\n expected " + exstr + "\n but got " + acstr + "\n (" + diffstr + ")");
}
};
@@ -63,11 +63,11 @@ if(false) Valid.json(PersonSchema).assert({ // now validate this JSON
// first test the validation routines
-if(Valid.json({a:1}).check({a:1}) !== undefined) throw "test() success needs to return undefined";
+if(Valid.json({a:1}).check({a:1}) !== undefined) throw Error("test() success needs to return undefined");
var result = DeepCompare(Valid.json({a:1}).check({a:2}), {'a': {value: 2, message: 'does not equal 1'}});
-if(result) throw "test() failure was wrong: " + result;
-if(Valid.json({a:1}).isValid({a:1}) !== true) throw "check() success needs to return true";
-if(Valid.json({a:1}).isValid({a:2}) !== false) throw "check() failure needs to return false";
+if(result) throw Error("test() failure was wrong: " + result);
+if(Valid.json({a:1}).isValid({a:1}) !== true) throw Error("check() success needs to return true");
+if(Valid.json({a:1}).isValid({a:2}) !== false) throw Error("check() failure needs to return false");
// now ensure Valid.json works

0 comments on commit e4a4947

Please sign in to comment.