Skip to content
Browse files

- Improved assertion messages, added custom message argument

  - Renamed assert[Not]Equals to assert[Not]Equal and made it more lax than the
    new assert[Not]Identical
  - Added more assertion functions
  • Loading branch information...
1 parent 8f22f48 commit 2541e58fcbb6c13e4ce13f6460ba8a586b71d414 @atesgoral committed Mar 25, 2009
View
4 jsunity/CHANGES.txt
@@ -1,3 +1,7 @@
+ - Improved assertion messages, added custom message argument
+ - Renamed assert[Not]Equals to assert[Not]Equal and made it more lax than the
+ new assert[Not]Identical
+ - Added more assertion functions
- Made missing test suite names undefined instead of empty string
- Fixed function probing logic so that an outer function doesn't shield
an inner function with the same name
View
160 jsunity/jsunity.js
@@ -9,70 +9,166 @@
*/
jsUnity = (function () {
+ function fmt(str) {
+ var a = Array.prototype.slice.call(arguments, 1);
+ return str.replace(/\?/g, function () { return a.shift(); });
+ }
+
+ function hash(v) {
+ if (v instanceof Object) {
+ var arr = [];
+
+ for (var p in v) {
+ arr.push(p);
+ arr.push(hash(v[p]));
+ }
+
+ return arr.join("#");
+ } else {
+ return String(v);
+ }
+ }
+
var defaultAssertions = {
- assertTrue: function (expr) {
- if (!expr) {
- throw "Expression does not evaluate to true";
+ assertException: function (fn, message) {
+ try {
+ fn instanceof Function && fn();
+ } catch (e) {
+ return;
+ }
+
+ throw fmt("?: (?) does not raise an exception or not a function",
+ message || "assertException", fn);
+ },
+
+ assertTrue: function (actual, message) {
+ if (!actual) {
+ throw fmt("?: (?) does not evaluate to true",
+ message || "assertTrue", actual);
}
},
- assertFalse: function (expr) {
- if (expr) {
- throw "Condition does not evaluate to false";
+ assertFalse: function (actual, message) {
+ if (actual) {
+ throw fmt("?: (?) does not evaluate to false",
+ message || "assertFalse", actual);
}
},
- assertEquals: function (expected, actual) {
+ assertIdentical: function (expected, actual, message) {
if (expected !== actual) {
- throw "Actual value does not match what's expected: [expected] "
- + expected + ", [actual] " + actual;
+ throw fmt("?: (?) is not identical to (?)",
+ message || "assertIdentical", actual, expected);
+ }
+ },
+
+ assertNotIdentical: function (expected, actual, message) {
+ if (expected === actual) {
+ throw fmt("?: (?) is identical to (?)",
+ message || "assertNotIdentical", actual, expected);
+ }
+ },
+
+ assertEqual: function (expected, actual, message) {
+ if (hash(expected) != hash(actual)) {
+ throw fmt("?: (?) is not equal to (?)",
+ message || "assertEqual", actual, expected);
}
},
- assertNotEquals: function (unexpected, actual) {
- if (unexpected === actual) {
- throw "Actual value matches the unexpected value: " + actual;
+ assertNotEqual: function (expected, actual, message) {
+ if (hash(expected) == hash(actual)) {
+ throw fmt("?: (?) is equal to (?)",
+ message || "assertNotEqual", actual, expected);
}
},
- assertNull: function (object) {
- if (object !== null) {
- throw "Object is not null";
+ assertMatch: function (re, actual, message) {
+ if (!re.test(actual)) {
+ throw fmt("?: (?) does not match (?)",
+ message || "assertMatch", actual, re);
+ }
+ },
+
+ assertNotMatch: function (re, actual, message) {
+ if (re.test(actual)) {
+ throw fmt("?: (?) matches (?)",
+ message || "assertNotMatch", actual, re);
+ }
+ },
+
+ assertTypeOf: function (typ, actual, message) {
+ if (typeof actual !== typ) {
+ throw fmt("?: (?) is not of type (?)",
+ message || "assertTypeOf", actual, typ);
+ }
+ },
+
+ assertNotTypeOf: function (typ, actual, message) {
+ if (typeof actual === typ) {
+ throw fmt("?: (?) is of type (?)",
+ message || "assertNotTypeOf", actual, typ);
+ }
+ },
+
+ assertInstanceOf: function (cls, actual, message) {
+ if (!(actual instanceof cls)) {
+ throw fmt("?: (?) is not an instance of (?)",
+ message || "assertInstanceOf", actual, cls);
+ }
+ },
+
+ assertNotInstanceOf: function (cls, actual, message) {
+ if (actual instanceof cls) {
+ throw fmt("?: (?) is an instance of (?)",
+ message || "assertNotInstanceOf", actual, cls);
+ }
+ },
+
+ assertNull: function (actual, message) {
+ if (actual !== null) {
+ throw fmt("?: (?) is not null",
+ message || "assertNull", actual);
}
},
- assertNotNull: function (object) {
- if (object === null) {
- throw "Object is null";
+ assertNotNull: function (actual, message) {
+ if (actual === null) {
+ throw fmt("?: (?) is null",
+ message || "assertNotNull", actual);
}
},
- assertUndefined: function (value) {
- if (value !== undefined) {
- throw "Value is not undefined";
+ assertUndefined: function (actual, message) {
+ if (actual !== undefined) {
+ throw fmt("?: (?) is not undefined",
+ message || "assertUndefined", actual);
}
},
- assertNotUndefined: function (value) {
- if (value === undefined) {
- throw "Value is undefined";
+ assertNotUndefined: function (actual, message) {
+ if (actual === undefined) {
+ throw fmt("?: (?) is undefined",
+ message || "assertNotUndefined", actual);
}
},
- assertNaN: function (value) {
- if (!isNaN(value)) {
- throw "Value is not NaN";
+ assertNaN: function (actual, message) {
+ if (!isNaN(actual)) {
+ throw fmt("?: (?) is not NaN",
+ message || "assertNaN", actual);
}
},
- assertNotNaN: function (value) {
- if (isNaN(value)) {
- throw "Value is NaN";
+ assertNotNaN: function (actual, message) {
+ if (isNaN(actual)) {
+ throw fmt("?: (?) is NaN",
+ message || "assertNotNaN", actual);
}
},
- fail: function () {
- throw "Test failed";
+ fail: function (message) {
+ throw message || "fail";
}
};
View
379 jsunity/test/assertionTestSuite.js
@@ -1,93 +1,372 @@
//<%
-function assertionTestSuite() {
- function assertException(fn) {
- var fail = false;
+var a = {};
+jsUnity.attachAssertions(a);
+function AssertionTestSuite() {
+ function checkMessageMarker(fn) {
try {
fn();
- fail = true;
} catch (e) {
- // Eat the exception
- }
-
- if (fail) {
- throw "An exception wasn't thrown";
+ a.assertMatch(/marker/, e);
}
}
- function testAssertTrue() {
- jsUnity.assertions.assertTrue(true);
+ function testAssertExceptionPositive() {
+ a.assertException(function () {
+ throw 1;
+ });
+ }
+
+ function testAssertExceptionNegative() {
+ a.assertException(function () {
+ a.assertException(function () {});
+ });
+ }
- assertException(function () { jsUnity.assertions.assertTrue(false); });
+ function testAssertExceptionMessage() {
+ checkMessageMarker(function () {
+ a.assertException(function () {}, "marker");
+ });
+ }
+
+ function testAssertTruePositive() {
+ a.assertTrue(true);
}
- function testAssertFalse() {
- jsUnity.assertions.assertFalse(false);
+ function testAssertTrueNegative() {
+ a.assertException(function () {
+ a.assertTrue(false);
+ });
+ }
+
+ function testAssertTrueMessage() {
+ checkMessageMarker(function () {
+ a.assertTrue(false, "marker");
+ });
+ }
+
+ function testAssertFalsePositive() {
+ a.assertFalse(false);
+ }
- assertException(function () { jsUnity.assertions.assertFalse(true); });
+ function testAssertFalseNegative() {
+ a.assertException(function () {
+ a.assertFalse(true);
+ });
}
- function testAssertEquals() {
- jsUnity.assertions.assertEquals(1, 1);
- var n = new Number(5);
- jsUnity.assertions.assertEquals(n, n);
- jsUnity.assertions.assertEquals(undefined, undefined);
+ function testAssertFalseMessage() {
+ checkMessageMarker(function () {
+ a.assertFalse(true, "marker");
+ });
+ }
+
+ function testAssertIdenticalPositive() {
+ a.assertIdentical(1, 1);
+ a.assertIdentical(null, null);
+ a.assertIdentical(undefined, undefined);
+ var obj = {};
+ a.assertIdentical(obj, obj);
+ }
+
+ function testAssertIdenticalNegative() {
+ a.assertException(function () {
+ a.assertIdentical(1, "1");
+ });
+ a.assertException(function () {
+ a.assertIdentical(null, undefined);
+ });
+ a.assertException(function () {
+ a.assertIdentical(false, 0);
+ });
+ }
+
+ function testAssertIdenticalMessage() {
+ checkMessageMarker(function () {
+ a.assertIdentical(1, "1", "marker");
+ });
+ }
+
+ function testAssertNotIdenticalPositive() {
+ a.assertNotIdentical("1", 1);
+ a.assertNotIdentical(undefined, null);
+ a.assertNotIdentical(1, true);
+ var obj1 = {};
+ var obj2 = {};
+ a.assertNotIdentical(obj1, obj2);
+ }
- assertException(function () { jsUnity.assertions.assertEquals("foo", "bar"); });
- assertException(function () { jsUnity.assertions.assertEquals(undefined, new Date()); });
- assertException(function () { jsUnity.assertions.assertEquals([42], undefined); });
+ function testAssertNotIdenticalNegative() {
+ a.assertException(function () {
+ a.assertNotIdentical(1, 1);
+ });
+ a.assertException(function () {
+ a.assertNotIdentical(null, null);
+ });
+ a.assertException(function () {
+ a.assertNotIdentical(undefined, undefined);
+ });
+ var obj = {};
+ a.assertException(function () {
+ a.assertNotIdentical(obj, obj);
+ });
+ }
+
+ function testAssertNotIdenticalMessage() {
+ checkMessageMarker(function () {
+ a.assertNotIdentical(1, 1, "marker");
+ });
}
- function testAssertNotEquals() {
- jsUnity.assertions.assertNotEquals(1, 2);
- jsUnity.assertions.assertNotEquals(new Number(5), new Number(6));
- jsUnity.assertions.assertNotEquals(undefined, "foo");
- jsUnity.assertions.assertNotEquals([42], undefined);
+ function testAssertEqualPositive() {
+ a.assertEqual(1, "1");
+ a.assertEqual({ a: 1, b: [ 2, 3 ] }, { a: 1, b: [ 2, 3 ] });
+ }
+
+ function testAssertEqualNegative() {
+ a.assertException(function () {
+ a.assertEqual("2", 1);
+ });
+ a.assertException(function () {
+ a.assertEqual({}, null);
+ });
+ a.assertException(function () {
+ a.assertEqual(undefined, null);
+ });
+ }
+
+ function testAssertEqualMessage() {
+ checkMessageMarker(function () {
+ a.assertEqual("2", 1, "marker");
+ });
+ }
+
+ function testAssertNotEqualPositive() {
+ a.assertNotEqual(1, "2");
+ a.assertNotEqual(null, {});
+ }
- assertException(function () { jsUnity.assertions.assertNotEquals(1, 1); });
- assertException(function () { jsUnity.assertions.assertNotEquals(undefined, undefined); });
+ function testAssertNotEqualNegative() {
+ a.assertException(function () {
+ a.assertNotEqual("2", 2);
+ });
+ a.assertException(function () {
+ a.assertNotEqual({ a: 1, b: [ 2, 3 ] }, { a: 1, b: [ 2, 3 ] });
+ });
}
- function testAssertNull() {
- jsUnity.assertions.assertNull(null);
+ function testAssertNotEqualMessage() {
+ checkMessageMarker(function () {
+ a.assertNotEqual("2", 2, "marker");
+ });
+ }
+
+ function testAssertMatchPositive() {
+ a.assertMatch(/es/, "test");
+ }
- assertException(function () { jsUnity.assertions.assertNull(5); });
+ function testAssertMatchNegative() {
+ a.assertException(function () {
+ a.assertMatch(/foo/, "test");
+ });
}
- function testAssertNotNull() {
- jsUnity.assertions.assertNotNull(3);
+ function testAssertMatchMessage() {
+ checkMessageMarker(function () {
+ a.assertMatch(/foo/, "test", "marker");
+ });
+ }
+
+ function testAssertNotMatchPositive() {
+ a.assertNotMatch(/foo/, "test");
+ }
- assertException(function () { jsUnity.assertions.assertNotNull(null); });
+ function testAssertNotMatchNegative() {
+ a.assertException(function () {
+ a.assertNotMatch(/es/, "test");
+ });
}
- function testAssertUndefined() {
- jsUnity.assertions.assertUndefined(undefined);
+ function testAssertNotMatchMessage() {
+ checkMessageMarker(function () {
+ a.assertNotMatch(/es/, "test", "marker");
+ });
+ }
+
+ function testAssertTypeOfPositive() {
+ a.assertTypeOf("string", "test");
+ }
- assertException(function () { jsUnity.assertions.assertUndefined(5); });
+ function testAssertTypeOfNegative() {
+ a.assertException(function () {
+ a.assertTypeOf("number", "test");
+ });
}
- function testAssertNotUndefined() {
- jsUnity.assertions.assertNotUndefined(3);
+ function testAssertTypeOfMessage() {
+ checkMessageMarker(function () {
+ a.assertTypeOf("number", "test", "marker");
+ });
+ }
+
+ function testAssertNotTypeOfPositive() {
+ a.assertNotTypeOf("string", 1);
+ }
- assertException(function () { jsUnity.assertions.assertNotUndefined(undefined); });
+ function testAssertNotTypeOfNegative() {
+ a.assertException(function () {
+ a.assertNotTypeOf("number", 1);
+ });
}
- function testAssertNaN() {
- jsUnity.assertions.assertNaN(NaN);
+ function testAssertNotTypeOfMessage() {
+ checkMessageMarker(function () {
+ a.assertNotTypeOf("number", 1, "marker");
+ });
+ }
- assertException(function () { jsUnity.assertions.assertNaN(42); });
+ function testAssertInstanceOfPositive() {
+ a.assertInstanceOf(String, new String("test"));
}
- function testAssertNotNaN() {
- jsUnity.assertions.assertNotNaN(42);
+ function testAssertInstanceOfNegative() {
+ a.assertException(function () {
+ a.assertInstanceOf(Number, {});
+ });
+ }
- assertException(function () { jsUnity.assertions.assertNotNaN(NaN); });
+ function testAssertInstanceOfMessage() {
+ checkMessageMarker(function () {
+ a.assertInstanceOf(Number, {}, "marker");
+ });
+ }
+
+ function testAssertNotInstanceOfPositive() {
+ a.assertNotInstanceOf(String, []);
+ }
+
+ function testAssertNotInstanceOfNegative() {
+ a.assertException(function () {
+ a.assertNotInstanceOf(Number, new Number(1));
+ });
+ }
+
+ function testAssertNotInstanceOfMessage() {
+ checkMessageMarker(function () {
+ a.assertNotInstanceOf(Number, new Number(1), "marker");
+ });
+ }
+
+ function testAssertNullPositive() {
+ a.assertNull(null);
+ }
+
+ function testAssertNullNegative() {
+ a.assertException(function () {
+ a.assertNull(1);
+ });
+ }
+
+ function testAssertNullMessage() {
+ checkMessageMarker(function () {
+ a.assertNull(1, "marker");
+ });
+ }
+
+ function testAssertNotNullPositive() {
+ a.assertNotNull(1);
+ }
+
+ function testAssertNotNullNegative() {
+ a.assertException(function () {
+ a.assertNotNull(null);
+ });
+ }
+
+ function testAssertNotNullMessage() {
+ checkMessageMarker(function () {
+ a.assertNotNull(null, "marker");
+ });
+ }
+
+ function testAssertUndefinedPositive() {
+ a.assertUndefined(undefined);
+ }
+
+ function testAssertUndefinedNegative() {
+ a.assertException(function () {
+ a.assertUndefined(1);
+ });
+ }
+
+ function testAssertUndefinedMessage() {
+ checkMessageMarker(function () {
+ a.assertUndefined(1, "marker");
+ });
+ }
+
+ function testAssertNotUndefinedPositive() {
+ a.assertNotUndefined(1);
+ }
+
+ function testAssertNotUndefinedNegative() {
+ a.assertException(function () {
+ a.assertNotUndefined(undefined);
+ });
+ }
+
+ function testAssertNotUndefinedMessage() {
+ checkMessageMarker(function () {
+ a.assertNotUndefined(undefined, "marker");
+ });
+ }
+
+ function testAssertNaNPositive() {
+ a.assertNaN(NaN);
+ a.assertNaN("test");
+ }
+
+ function testAssertNaNNegative() {
+ a.assertException(function () {
+ a.assertNaN(1);
+ });
+ }
+
+ function testAssertNaNMessage() {
+ checkMessageMarker(function () {
+ a.assertNaN(1, "marker");
+ });
+ }
+
+ function testAssertNotNaNPositive() {
+ a.assertNotNaN(1);
+ }
+
+ function testAssertNotNaNNegative() {
+ a.assertException(function () {
+ a.assertNotNaN(NaN);
+ });
+ a.assertException(function () {
+ a.assertNotNaN("test");
+ });
+ }
+
+ function testAssertNotNaNMessage() {
+ checkMessageMarker(function () {
+ a.assertNotNaN(NaN, "marker");
+ });
}
function testFail() {
- var pass = true;
+ a.assertException(function () {
+ a.fail();
+ });
+ }
- assertException(function () { jsUnity.assertions.fail(); });
+ function testFailMessage() {
+ checkMessageMarker(function () {
+ a.fail("marker");
+ });
}
}
//%>
View
192 jsunity/test/coreTestSuite.js
@@ -10,22 +10,25 @@ var global = {
tearDown: tearDown
};
+var a = {};
+jsUnity.attachAssertions(a);
+
function checkAssertions(scope) {
for (var fn in jsUnity.assertions) {
- jsUnity.assertions.assertEquals(jsUnity.assertions[fn], scope[fn]);
+ a.assertIdentical(jsUnity.assertions[fn], scope[fn]);
}
}
-function coreTestSuite() {
+function CoreTestSuite() {
function checkResults(results, suiteName) {
- jsUnity.assertions.assertTrue(results instanceof jsUnity.TestResults);
- jsUnity.assertions.assertEquals(suiteName || "", results.suiteName);
- jsUnity.assertions.assertEquals(3, results.total);
- jsUnity.assertions.assertEquals(2, results.passed);
- jsUnity.assertions.assertEquals(1, results.failed);
-
- jsUnity.assertions.assertEquals(3, setUps);
- jsUnity.assertions.assertEquals(3, tearDowns);
+ a.assertInstanceOf(jsUnity.TestResults, results);
+ a.assertIdentical(suiteName || "", results.suiteName);
+ a.assertIdentical(3, results.total);
+ a.assertIdentical(2, results.passed);
+ a.assertIdentical(1, results.failed);
+
+ a.assertIdentical(3, setUps);
+ a.assertIdentical(3, tearDowns);
}
function setUp() {
@@ -38,7 +41,7 @@ function coreTestSuite() {
delete origLog;
}
- function testSetUpTearDown() {
+ function testSetUpTearDownCalled() {
function setUpTearDownTestSuite() {
function setUp() {
calls.push("setUp");
@@ -57,11 +60,11 @@ function coreTestSuite() {
jsUnity.run(setUpTearDownTestSuite);
- jsUnity.assertions.assertEquals("setUp,testDummy,tearDown",
+ a.assertIdentical("setUp,testDummy,tearDown",
calls.join(","));
}
- function testLog() {
+ function testLogCalled() {
var hijackedLog = jsUnity.log;
var hijackedGetDate = jsUnity.env.getDate;
@@ -80,8 +83,7 @@ function coreTestSuite() {
jsUnity.log = hijackedLog;
jsUnity.env.getDate = hijackedGetDate;
- jsUnity.assertions.assertTrue(Boolean(results));
- jsUnity.assertions.assertEquals(
+ a.assertIdentical(
"Running unnamed test suite\n"
+ "0 tests found\n"
+ "0 tests passed\n"
@@ -90,7 +92,7 @@ function coreTestSuite() {
logStrs.join("\n"));
}
- function testError() {
+ function testErrorCalled() {
var hijackedError = jsUnity.error;
var errorStr;
@@ -103,8 +105,8 @@ function coreTestSuite() {
jsUnity.error = hijackedError;
- jsUnity.assertions.assertFalse(results);
- jsUnity.assertions.assertTrue(errorStr.length > 0);
+ a.assertIdentical(false, results);
+ a.assertTrue(errorStr.length > 0);
}
function testAttachAssertionsDefaultScope() {
@@ -135,13 +137,13 @@ function coreTestSuite() {
var testSuite = jsUnity.compile(origTestSuite);
- jsUnity.assertions.assertTrue(testSuite instanceof jsUnity.TestSuite);
- jsUnity.assertions.assertEquals("TestSuite", testSuite.suiteName);
- jsUnity.assertions.assertEquals(scope, testSuite.scope);
- jsUnity.assertions.assertEquals(global.setUp, testSuite.setUp);
- jsUnity.assertions.assertEquals(global.tearDown, testSuite.tearDown);
- jsUnity.assertions.assertEquals("testDummy", testSuite.tests[0].name);
- jsUnity.assertions.assertEquals(testDummy, testSuite.tests[0].fn);
+ a.assertInstanceOf(jsUnity.TestSuite, testSuite);
+ a.assertIdentical("TestSuite", testSuite.suiteName);
+ a.assertIdentical(scope, testSuite.scope);
+ a.assertIdentical(global.setUp, testSuite.setUp);
+ a.assertIdentical(global.tearDown, testSuite.tearDown);
+ a.assertIdentical("testDummy", testSuite.tests[0].name);
+ a.assertIdentical(testDummy, testSuite.tests[0].fn);
}
function testCompileNamedFunction() {
@@ -160,17 +162,13 @@ function coreTestSuite() {
var internals = namedTestSuite();
var testSuite = jsUnity.compile(namedTestSuite);
- jsUnity.assertions.assertTrue(testSuite instanceof jsUnity.TestSuite);
- jsUnity.assertions.assertEquals("namedTestSuite", testSuite.suiteName);
- jsUnity.assertions.assertEquals("object", typeof testSuite.scope);
- jsUnity.assertions.assertEquals(internals.setUp.toString(),
- testSuite.setUp.toString());
- jsUnity.assertions.assertEquals(internals.tearDown.toString(),
- testSuite.tearDown.toString());
- jsUnity.assertions.assertEquals("testDummy",
- testSuite.tests[0].name);
- jsUnity.assertions.assertEquals(internals.testDummy.toString(),
- testSuite.tests[0].fn.toString());
+ a.assertInstanceOf(jsUnity.TestSuite, testSuite);
+ a.assertIdentical("namedTestSuite", testSuite.suiteName);
+ a.assertTypeOf("object", testSuite.scope);
+ a.assertEqual(internals.setUp, testSuite.setUp);
+ a.assertEqual(internals.tearDown, testSuite.tearDown);
+ a.assertIdentical("testDummy", testSuite.tests[0].name);
+ a.assertEqual(internals.testDummy, testSuite.tests[0].fn);
}
function testCompileAnonymousFunction() {
@@ -189,16 +187,16 @@ function coreTestSuite() {
var internals = anonymousTestSuite();
var testSuite = jsUnity.compile(anonymousTestSuite);
- jsUnity.assertions.assertTrue(testSuite instanceof jsUnity.TestSuite);
- jsUnity.assertions.assertUndefined(testSuite.suiteName);
- jsUnity.assertions.assertEquals("object", typeof testSuite.scope);
- jsUnity.assertions.assertEquals(internals.setUp.toString(),
+ a.assertTrue(testSuite instanceof jsUnity.TestSuite);
+ a.assertUndefined(testSuite.suiteName);
+ a.assertIdentical("object", typeof testSuite.scope);
+ a.assertIdentical(internals.setUp.toString(),
testSuite.setUp.toString());
- jsUnity.assertions.assertEquals(internals.tearDown.toString(),
+ a.assertIdentical(internals.tearDown.toString(),
testSuite.tearDown.toString());
- jsUnity.assertions.assertEquals("testDummy",
+ a.assertIdentical("testDummy",
testSuite.tests[0].name);
- jsUnity.assertions.assertEquals(internals.testDummy.toString(),
+ a.assertIdentical(internals.testDummy.toString(),
testSuite.tests[0].fn.toString());
}
@@ -211,13 +209,13 @@ function coreTestSuite() {
var testSuite = jsUnity.compile(arrayTestSuite);
- jsUnity.assertions.assertTrue(testSuite instanceof jsUnity.TestSuite);
- jsUnity.assertions.assertUndefined(testSuite.suiteName);
- jsUnity.assertions.assertEquals("object", typeof testSuite.scope);
- jsUnity.assertions.assertEquals(global.setUp, testSuite.setUp);
- jsUnity.assertions.assertEquals(global.tearDown, testSuite.tearDown);
- jsUnity.assertions.assertEquals("testGlobalPass1", testSuite.tests[0].name);
- jsUnity.assertions.assertEquals(testGlobalPass1, testSuite.tests[0].fn);
+ a.assertTrue(testSuite instanceof jsUnity.TestSuite);
+ a.assertUndefined(testSuite.suiteName);
+ a.assertIdentical("object", typeof testSuite.scope);
+ a.assertIdentical(global.setUp, testSuite.setUp);
+ a.assertIdentical(global.tearDown, testSuite.tearDown);
+ a.assertIdentical("testGlobalPass1", testSuite.tests[0].name);
+ a.assertIdentical(testGlobalPass1, testSuite.tests[0].fn);
}
function testCompileArrayOfStrings() {
@@ -229,13 +227,13 @@ function coreTestSuite() {
var testSuite = jsUnity.compile(arrayTestSuite);
- jsUnity.assertions.assertTrue(testSuite instanceof jsUnity.TestSuite);
- jsUnity.assertions.assertUndefined(testSuite.suiteName);
- jsUnity.assertions.assertEquals("object", typeof testSuite.scope);
- jsUnity.assertions.assertEquals(global.setUp, testSuite.setUp);
- jsUnity.assertions.assertEquals(global.tearDown, testSuite.tearDown);
- jsUnity.assertions.assertEquals("testGlobalPass1", testSuite.tests[0].name);
- jsUnity.assertions.assertEquals(testGlobalPass1, testSuite.tests[0].fn);
+ a.assertTrue(testSuite instanceof jsUnity.TestSuite);
+ a.assertUndefined(testSuite.suiteName);
+ a.assertIdentical("object", typeof testSuite.scope);
+ a.assertIdentical(global.setUp, testSuite.setUp);
+ a.assertIdentical(global.tearDown, testSuite.tearDown);
+ a.assertIdentical("testGlobalPass1", testSuite.tests[0].name);
+ a.assertIdentical(testGlobalPass1, testSuite.tests[0].fn);
}
function testCompileObject() {
@@ -248,13 +246,13 @@ function coreTestSuite() {
var testSuite = jsUnity.compile(objectTestSuite);
- jsUnity.assertions.assertTrue(testSuite instanceof jsUnity.TestSuite);
- jsUnity.assertions.assertEquals("TestSuite", testSuite.suiteName);
- jsUnity.assertions.assertEquals(objectTestSuite, testSuite.scope);
- jsUnity.assertions.assertEquals(global.setUp, testSuite.setUp);
- jsUnity.assertions.assertEquals(global.tearDown, testSuite.tearDown);
- jsUnity.assertions.assertEquals("testGlobalPass1", testSuite.tests[0].name);
- jsUnity.assertions.assertEquals(testGlobalPass1, testSuite.tests[0].fn);
+ a.assertTrue(testSuite instanceof jsUnity.TestSuite);
+ a.assertIdentical("TestSuite", testSuite.suiteName);
+ a.assertIdentical(objectTestSuite, testSuite.scope);
+ a.assertIdentical(global.setUp, testSuite.setUp);
+ a.assertIdentical(global.tearDown, testSuite.tearDown);
+ a.assertIdentical("testGlobalPass1", testSuite.tests[0].name);
+ a.assertIdentical(testGlobalPass1, testSuite.tests[0].fn);
}
function testCompileString() {
@@ -263,29 +261,29 @@ function coreTestSuite() {
var testSuite = jsUnity.compile(stringTestSuite);
- jsUnity.assertions.assertTrue(testSuite instanceof jsUnity.TestSuite);
- jsUnity.assertions.assertUndefined(testSuite.suiteName);
- jsUnity.assertions.assertEquals("object", typeof testSuite.scope);
- jsUnity.assertions.assertEquals(global.setUp.toString(),
+ a.assertTrue(testSuite instanceof jsUnity.TestSuite);
+ a.assertUndefined(testSuite.suiteName);
+ a.assertIdentical("object", typeof testSuite.scope);
+ a.assertIdentical(global.setUp.toString(),
testSuite.setUp.toString());
- jsUnity.assertions.assertEquals(global.tearDown.toString(),
+ a.assertIdentical(global.tearDown.toString(),
testSuite.tearDown.toString());
- jsUnity.assertions.assertEquals("testGlobalPass1",
+ a.assertIdentical("testGlobalPass1",
testSuite.tests[0].name);
- jsUnity.assertions.assertEquals(testGlobalPass1.toString(),
+ a.assertIdentical(testGlobalPass1.toString(),
testSuite.tests[0].fn.toString());
}
function testCompileNumber() {
try {
jsUnity.compile(42);
- jsUnity.assertions.fail();
+ a.fail();
} catch (e) {
// pass
}
}
- function testRunTestSuite() {
+ function testRunTestSuiteReturnsResults() {
setUps = 0;
tearDowns = 0;
@@ -299,7 +297,7 @@ function coreTestSuite() {
checkResults(jsUnity.run(testSuite), "TestSuite");
}
- function testRunNamedFunction() {
+ function testRunNamedFunctionReturnsResults() {
setUps = 0;
tearDowns = 0;
@@ -314,7 +312,7 @@ function coreTestSuite() {
checkResults(jsUnity.run(namedTestSuite), "namedTestSuite");
}
- function testRunAnonymousFunction() {
+ function testRunAnonymousFunctionReturnsResults() {
setUps = 0;
tearDowns = 0;
@@ -329,7 +327,7 @@ function coreTestSuite() {
checkResults(jsUnity.run(anonymousTestSuite));
}
- function testRunArrayOfFunctions() {
+ function testRunArrayOfFunctionsReturnsResults() {
setUps = 0;
tearDowns = 0;
@@ -344,7 +342,7 @@ function coreTestSuite() {
checkResults(jsUnity.run(arrayTestSuite));
}
- function testRunArrayOfStrings() {
+ function testRunArrayOfStringsReturnsResults() {
setUps = 0;
tearDowns = 0;
@@ -359,7 +357,7 @@ function coreTestSuite() {
checkResults(jsUnity.run(arrayTestSuite));
}
- function testRunObject() {
+ function testRunObjectReturnsResults() {
setUps = 0;
tearDowns = 0;
@@ -375,7 +373,7 @@ function coreTestSuite() {
checkResults(jsUnity.run(objectTestSuite), "objectTestSuite");
}
- function testRunString() {
+ function testRunStringReturnsResults() {
setUps = 0;
tearDowns = 0;
@@ -389,62 +387,62 @@ function coreTestSuite() {
checkResults(jsUnity.run(stringTestSuite));
}
- function testRunNumber() {
- jsUnity.assertions.assertFalse(jsUnity.run(42));
+ function testRunNumberFails() {
+ a.assertFalse(jsUnity.run(42));
}
- function testRunMultiple() {
+ function testRunMultipleReturnsResults() {
function namedTestSuite1() {
function testThatPasses() {}
}
function namedTestSuite2() {
- function testThatFails() { jsUnity.assertions.fail(); }
+ function testThatFails() { a.fail(); }
}
var anonymousTestSuite = function () {
}
var results = jsUnity.run(
namedTestSuite1, namedTestSuite2, anonymousTestSuite);
- jsUnity.assertions.assertEquals("namedTestSuite1,namedTestSuite2,",
+ a.assertIdentical("namedTestSuite1,namedTestSuite2,",
results.suiteName);
- jsUnity.assertions.assertEquals(2, results.total);
- jsUnity.assertions.assertEquals(1, results.passed);
- jsUnity.assertions.assertEquals(1, results.failed);
+ a.assertIdentical(2, results.total);
+ a.assertIdentical(1, results.passed);
+ a.assertIdentical(1, results.failed);
}
function testRunTestSuiteBindsGivenScopeAsTestScope() {
var testSuite = new jsUnity.TestSuite("TestSuite", { marker: true });
testSuite.tests.push({
name: "testMarker",
fn: function () {
- jsUnity.assertions.assertTrue(this.marker);
+ a.assertTrue(this.marker);
}
});
var results = jsUnity.run(testSuite);
- jsUnity.assertions.assertEquals(1, results.passed);
+ a.assertIdentical(1, results.passed);
}
function testRunFunctionWontBindFunctionAsTestScope() {
function testSuite() {
function testMarker() {
- jsUnity.assertions.assertTrue(this.marker);
+ a.assertTrue(this.marker);
}
}
testSuite.marker = true;
var results = jsUnity.run(testSuite);
- jsUnity.assertions.assertEquals(1, results.failed);
+ a.assertIdentical(1, results.failed);
}
function testRunArrayWontBindArrayAsTestScope() {
function testMarker() {
- jsUnity.assertions.assertTrue(this.marker);
+ a.assertTrue(this.marker);
}
var testSuite = [ testMarker ];
@@ -453,31 +451,31 @@ function coreTestSuite() {
var results = jsUnity.run(testSuite);
- jsUnity.assertions.assertEquals(1, results.failed);
+ a.assertIdentical(1, results.failed);
}
function testRunStringWontBindStringAsTestScope() {
var testSuite = "function testMarker() {"
- + "jsUnity.assertions.assertTrue(this.marker);"
+ + "a.assertTrue(this.marker);"
+ "}";
testSuite.marker = true;
var results = jsUnity.run(testSuite);
- jsUnity.assertions.assertEquals(1, results.failed);
+ a.assertIdentical(1, results.failed);
}
function testRunObjectBindsObjectAsTestScope() {
var results = jsUnity.run({
marker: true,
testMarker: function () {
- jsUnity.assertions.assertTrue(this.marker);
+ a.assertTrue(this.marker);
}
});
- jsUnity.assertions.assertEquals(1, results.passed);
+ a.assertIdentical(1, results.passed);
}
}
//%>
View
2 jsunity/test/runAllTestSuites.asp
@@ -11,7 +11,7 @@
<body>
<%
jsUnity.log = function (s) { Response.Write("<div>" + s + "</div>"); }
-jsUnity.run(assertionTestSuite, coreTestSuite);
+jsUnity.run(AssertionTestSuite, CoreTestSuite);
%>
</body>
</html>
View
2 jsunity/test/runAllTestSuites.html
@@ -8,7 +8,7 @@
<body>
<script type="text/javascript">
jsUnity.log = function (s) { document.write("<div>" + s + "</div>"); }
- jsUnity.run(assertionTestSuite, coreTestSuite);
+ jsUnity.run(AssertionTestSuite, CoreTestSuite);
</script>
</body>
</html>
View
2 jsunity/test/runAllTestSuites.shell.js
@@ -3,4 +3,4 @@ load("assertionTestSuite.js");
load("coreTestSuite.js");
jsUnity.log = function (s) { print(s); };
-jsUnity.run(assertionTestSuite, coreTestSuite);
+jsUnity.run(AssertionTestSuite, CoreTestSuite);
View
2 jsunity/test/runAllTestSuites.wsf
@@ -8,7 +8,7 @@
<![CDATA[
var output = [];
jsUnity.log = function (s) { output.push(s); }
-jsUnity.run(assertionTestSuite, coreTestSuite);
+jsUnity.run(AssertionTestSuite, CoreTestSuite);
WScript.Echo(output.join("\r\n"));
]]>
</script>

0 comments on commit 2541e58

Please sign in to comment.
Something went wrong with that request. Please try again.