Skip to content

Commit

Permalink
improved assertion error messages. added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Jun 13, 2010
1 parent 72eecd7 commit f10884d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/assert/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ assert.matches = assert.match;

assert.isTrue = function (actual, message) {
if (actual !== true) {
assert.fail(actual, true, message || "expected {actual} to be {expected}", "===", assert.isTrue);
assert.fail(actual, true, message || "expected {expected}, got {actual}", "===", assert.isTrue);
}
};
assert.isFalse = function (actual, message) {
if (actual !== false) {
assert.fail(actual, false, message || "expected {actual} to be {expected}", "===", assert.isFalse);
assert.fail(actual, false, message || "expected {expected}, got {actual}", "===", assert.isFalse);
}
};
assert.isZero = function (actual, message) {
Expand All @@ -47,7 +47,7 @@ assert.isZero = function (actual, message) {
};
assert.isNotZero = function (actual, message) {
if (actual === 0) {
assert.fail(actual, 0, message || "expected {expected}, got {actual}", "===", assert.isNotZero);
assert.fail(actual, 0, message || "expected non-zero value, got {actual}", "===", assert.isNotZero);
}
};

Expand Down Expand Up @@ -117,12 +117,12 @@ assert.isNaN = function (actual, message) {
};
assert.isNull = function (actual, message) {
if (actual !== null) {
assert.fail(actual, null, message || "expected {actual} to be {expected}", "===", assert.isNull);
assert.fail(actual, null, message || "expected {expected}, got {actual}", "===", assert.isNull);
}
};
assert.isNotNull = function (actual, message) {
if (actual === null) {
assert.fail(actual, null, message || "expected {actual} to not be {expected}", "===", assert.isNotNull);
assert.fail(actual, null, message || "expected non-null value, got {actual}", "===", assert.isNotNull);
}
};
assert.isUndefined = function (actual, message) {
Expand Down
10 changes: 10 additions & 0 deletions test/vows-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ vows.describe("Vows").addVows({
assert.isNumber(0);
assert.isNaN(0/0);
},
"testing value": function (it) {
assert.isFalse(false);
assert.isTrue(true);
assert.isZero(0);
assert.isNotZero(1);
assert.isNull(null);
assert.isNotNull(0);
assert.greater(5, 4);
assert.lesser(4, 5);
},
"testing emptiness": function (it) {
assert.isEmpty({});
assert.isEmpty([]);
Expand Down

0 comments on commit f10884d

Please sign in to comment.