Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

assertEqual

Assertions API here is very messy...
  • Loading branch information...
commit 779f9ce02dd13e9d394dbaccb06e8a04b07993ec 1 parent b5b1e62
@joelplane joelplane authored
Showing with 22 additions and 3 deletions.
  1. +4 −3 assertion.js
  2. +17 −0 test.js
  3. +1 −0  tests/noodleTestExampleTest.js
View
7 assertion.js
@@ -1,10 +1,11 @@
module.exports = (function(){
var sys = require('sys');
- function Assertion(testCase, assertMethod, args, tester) {
+ function Assertion(testCase, assertMethod, args, tester, failureMessageFunction) {
this.testCase = testCase;
this.assertMethod = assertMethod;
this.args = args;
this.tester = tester;
+ this.failureMessageFunction = failureMessageFunction;
this.passed = null;
var numberOfStackLinesToSkip = 1 /* First line which is just the name of the fake error we created: "Error" */
+ 1 /* Call to here */
@@ -17,10 +18,10 @@ module.exports = (function(){
this.passed = !!this.tester();
};
Assertion.prototype.failureMessage = function() {
- return "Expected first argument to evaluate to true";
+ return this.failureMessageFunction(this.args);
};
Assertion.prototype.callString = function() {
- return this.assertMethod + '(' + sys.inspect(this.args[0]) + ')'
+ return this.assertMethod;
};
return Assertion;
})();
View
17 test.js
@@ -33,6 +33,23 @@ module.exports = (function(Assertion, testQueue, timeout){
Test.prototype.assert = function(condition) {
var a = new Assertion(this, 'assert', [condition], function() {
return condition;
+ }, function(args) {
+ return "Expected first argument to evaluate to true";
+ });
+ a.execute();
+ if (a.passed) {
+ this.passes.push(a);
+ this.emit('assertionPassed', {context: this.context});
+ } else {
+ this.failures.push(a);
+ this.emit('assertionFailed', {context: this.context});
+ }
+ };
+ Test.prototype.assertEqual = function(expected, actual) {
+ var a = new Assertion(this, 'assertEqual', [expected, actual], function() {
+ return expected == actual;
+ }, function(args) {
+ return "Expected " + sys.inspect(expected) + ", but got " + sys.inspect(actual);
});
a.execute();
if (a.passed) {
View
1  tests/noodleTestExampleTest.js
@@ -7,6 +7,7 @@ doSomethingAsychronously(function() {
this.it("should do something", function(done) {
this.assert(true);
this.assert(false);
+ this.assertEqual("123", 135);
//done();
setTimeout(done, 1000);
});
Please sign in to comment.
Something went wrong with that request. Please try again.