Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 8a966d7491
...
compare: e2308a90f8
  • 5 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Showing with 747 additions and 34 deletions.
  1. +95 −2 README.md
  2. +187 −24 src/sink.js
  3. +1 −1  tests/tests.html
  4. +464 −7 tests/tests.js
View
97 README.md
@@ -3,7 +3,7 @@ Sink Test
An Asynchronous JavaScript Unit Testing Framework designed to run headless, or in the browser.
-Sink test is used to test JavaScript that is run asynchronously whereby you tell the test a number of expectations and Sink will tell you if they each pass successfully.
+Sink test is used to test JavaScript that is run asynchronously whereby you can specify the number of expectations and Sink will tell you if they each pass successfully or call an optional `complete()` callback to indicate test completion.
How to write a Sink test
------------------------
@@ -15,6 +15,16 @@ test('should have foo', 2, function() {
assert(resp.text, 'success', 'should have success')
})
})
+
+// alternatively:
+
+test('should have foo', function(complete) {
+ $.ajax('/foo', function(resp) {
+ ok(resp.stat == '200')
+ assert(resp.text, 'success', 'should have success')
+ complete()
+ })
+})
```
Loading a suite of tests
@@ -73,4 +83,87 @@ in your terminal
$ node path/to/my/tests.js
-Happy testing!
+
+Advanced assertion support
+--------------------------
+
+Sink Test follows most of the assert module specified in the [CommonJS Unit-Testing/1.0 assert module](http://wiki.commonjs.org/wiki/Unit_Testing/1.0) and gives you additional convenience assertions plus an API to define your own assertions.
+
+Basic assert calls perform a strict equals:
+
+``` js
+assert(actual, expected, message); // performs: actual === expected
+```
+
+The `assert` method is extended, giving you aliases for the above:
+
+``` js
+assert.same(actual, expected, message);
+assert.strictEqual(actual, expected, message);
+// and the inverse:
+assert.notSame(actual, expected, message);
+assert.notStrictEqual(actual, expected, message);
+```
+
+And also an alias for the simple boolean `ok` method:
+
+``` js
+assert.ok(value, message)
+```
+
+A non-strict deep equals is available via:
+
+``` js
+assert.equals(actual, expected, message);
+assert.deepEqual(actual, expected, message);
+// and the inverse:
+assert.notEqual(actual, expected, message);
+```
+
+And many additional assertions to make your tests clear and obvious:
+
+``` js
+assert.typeOf(value, type, message); // performs a "typeof value == type"
+assert.notTypeOf(value, type, message);
+assert.isDefined(value, message);
+assert.isUndefined(value, message);
+assert.isNull(value, message);
+assert.isNotNull(value, message);
+assert.isObject(value, message);
+assert.isFunction(value, message);
+assert.isString(value, message);
+assert.isNumber(value, message);
+assert.isTrue(value, message);
+assert.isFalse(value, message);
+assert.isBoolean(value, message);
+assert.isArray(value, message);
+assert.isElement(value, message); // is the value a DOM element
+```
+
+The *message* parameter on all assertions is optional.
+
+### Custom assertions
+
+When you have a complex condition to assert, you can define a custom assertion for it with the `assert.add()` method.
+
+Simply provide your assertion name and the handler function. Handler functions can take one or two arguments:
+
+``` js
+// single-argument form:
+assert.add('isUpperCaseString', function (value) {
+ return typeof value == 'string' && value.toUpperCase() === value;
+});
+// use it:
+assert.isUpperCaseString('this will fail', 'should be an upper-case string'); // → fail
+assert.isUpperCaseString('THIS WILL PASS', 'should be an upper-case string'); // → pass
+
+// dual-argument form:
+assert.add('matchesRegex', function (actual, regex) {
+ return typeof actual == 'string' && regex.test(actual);
+});
+// use it:
+assert.matchesRegex('this will pass', / [wil]+ /, 'should match my " [wil]+ " regex');
+```
+
+
+Happy testing!
View
211 src/sink.js
@@ -79,9 +79,38 @@
}
function _test(name, expect, fn) {
+ var li, check, start
+ , checker = function () {
+ if (sink.timeout && (+new Date - start > sink.timeout)) {
+ failure(li, check)
+ after()
+ } else {
+ if (fail) {
+ failure(li, check)
+ after()
+ } else if (!total) {
+ after()
+ pass(li, check)
+ } else {
+ setTimeout(arguments.callee, 10)
+ }
+ }
+ }
+ , complete = function () {
+ if (total == -1)
+ ok(false, 'No expectations!')
+ total = 0
+ }
+
before()
- total = expect
- var li, check, start = +new Date
+
+ if (typeof expect == 'function') {
+ fn = expect
+ total = -1
+ } else {
+ total = expect
+ }
+
if (!isHeadless) {
li = document.createElement('li')
li.innerHTML = name + ' ... <span>o</span><ul></ul>'
@@ -93,23 +122,10 @@
console.log(logKey + (name + '...').yellow)
}
- fn()
- setTimeout(function() {
- if (sink.timeout && (+new Date - start > sink.timeout)) {
- failure(li, check)
- after()
- } else {
- if (fail) {
- failure(li, check)
- after()
- } else if (!total) {
- after()
- pass(li, check)
- } else {
- setTimeout(arguments.callee, 10)
- }
- }
- }, 10)
+ start = +new Date
+ fn.apply(null, total == -1 ? [ complete ] : [])
+
+ setTimeout(checker, 10)
}
function test(name, expect, fn) {
@@ -130,17 +146,39 @@
}
}
- function assert(actual, expected, msg) {
- var b = actual === expected
- , message = b ? '' : '<b>actual: ' + actual.toString() + '</b><b>expected: ' + expected.toString() + '</b>'
+ function same(actual, expected) {
+ return actual === expected
+ }
+
+ var toPrintableString = typeof JSON !== 'undefined' && JSON.stringify ? function(o) {
+ if (o instanceof RegExp) return o.toString()
+ return JSON.stringify(o)
+ } : function(o) { return Object.prototype.toString.call(o) }
+
+ function assert(actual, expected, msg, type, fn) {
+ if (typeof type === 'undefined') type = 'same'
+ var b = (fn || same)(actual, expected)
+ , actualStr = toPrintableString(actual)
+ , expectedStr = toPrintableString(expected)
+ , typeStr = 'assert.' + type
+ if (assert.__negateNext) { // a hack to help with testing assert negatives
+ b = !b
+ typeStr = '!' + typeStr
+ delete assert.__negateNext
+ }
if (isHeadless) {
- message = b ? '' : '\n\tactual: ' + actual.toString() + '\n\texpected: ' + expected.toString()
+ var message = b ? '' :
+ '\n\t[' + typeStr + ']\n\tactual: ' + actualStr +
+ (fn && fn.length === 1 ? '' : '\n\texpected: ' + expectedStr)
if (b) console.log(logKey + msg + (message + '').green)
else console.log(logKey + msg + (message + '').red)
} else {
var li = document.createElement('li')
+ , message =
+ '<b>[' + typeStr + ']</b><b>actual: ' + actualStr +
+ (fn && fn.length === 1 ? '' : '</b><b>expected: ' + expectedStr + '</b>')
li.className = b ? 'pass' : 'fail'
- li.innerHTML = msg + ' ' + message + ' ' + '<em class="marker">' + (b ? '' : '') + '</em>'
+ li.innerHTML = (msg || '') + ' ' + message + ' ' + '<em class="marker">' + (b ? '' : '') + '</em>'
item.appendChild(li)
}
@@ -224,4 +262,129 @@
context.sink.timeout = 10000
}
+ //------------------- ASSERTIONS ----------------------//
+
+ // The following code is heavily inspired by BusterJS assertions by @cjno and @augustl
+ // These assertions are mostly compatible with CommonJS Unit-Testing/1.0.
+
+ var element = typeof document !== 'undefined' && document.createElement('p')
+
+ assert.add = function (type, fn) {
+ assert[type] = function(actual, expected, msg) {
+ if (fn.length === 1) {
+ msg = expected
+ expected = undefined
+ }
+ return assert(actual, expected, msg, type, fn)
+ }
+ }
+
+ function isElement(o) {
+ if (!o || !element || !o.nodeType || o.nodeType !== 1) return false
+ try {
+ o.appendChild(p)
+ o.removeChild(p)
+ } catch (ex) { return false }
+ return true
+ }
+
+ function isArray(o) {
+ return Object.prototype.toString.call(o) === '[object Array]'
+ }
+
+ function isDate(o) {
+ return typeof o.getTime == "function" && o.getTime() == o.valueOf()
+ }
+
+ function keys(o) {
+ var k = []
+ for (var p in o) {
+ if (Object.prototype.hasOwnProperty.call(o, p))
+ k.push(p)
+ }
+ return k
+ }
+
+ // yuk, an approximation of a CommonJS deepEqual method, not recursive-safe
+ function equal(actual, expected) {
+ if (actual === expected) return true
+ if (actual == null || expected == null)
+ return actual == expected
+ if (isElement(actual) || isElement(expected)) return false
+ if (isDate(actual) || isDate(expected))
+ return isDate(actual) && isDate(expected) && actual.getTime() === expected.getTime();
+ if (actual instanceof RegExp && expected instanceof RegExp)
+ return actual.toString() !== expected.toString()
+ if ((typeof actual !== 'object' || typeof expected !== 'object') &&
+ !isArray(actual) && !isArray(expected))
+ return actual == expected // coerce
+ if (typeof actual !== typeof expected) return false
+ var actualKeys = keys(actual)
+ , expectedKeys = keys(expected)
+ if (actualKeys.length !== expectedKeys.length) return false
+ var key, i = 0
+ for (; i < expectedKeys.length; i++) {
+ key = expectedKeys[i]
+ if (!Object.prototype.hasOwnProperty.call(actual, key) || !equal(actual[key], expected[key]))
+ return false
+ }
+ return true
+ }
+
+ assert.add('ok', function(actual) { return actual }, true)
+ assert.add('same', same)
+ assert.add('strictEqual', same)
+ assert.add('notStrictEqual', function(actual, expected) {
+ return !same(actual, expected)
+ })
+ assert.add('notSame', function(actual, expected) {
+ return !same(actual, expected)
+ })
+ assert.add('equal', equal)
+ assert.add('deepEqual', equal)
+ assert.add('notEqual', function(actual, expected) {
+ return !equal(actual, expected)
+ })
+ assert.add('typeOf', function(actual, expected) {
+ return typeof actual === expected
+ })
+ assert.add('notTypeOf', function(actual, expected) {
+ return typeof actual !== expected
+ })
+ assert.add('isDefined', function(actual) {
+ return typeof actual !== 'undefined'
+ })
+ assert.add('isUndefined', function(actual) {
+ return typeof actual === 'undefined'
+ })
+ assert.add('isNull', function(actual) {
+ return actual === null
+ })
+ assert.add('isNotNull', function(actual) {
+ return actual !== null
+ })
+ assert.add('isObject', function(actual) {
+ return typeof actual === 'object' && !!actual
+ })
+ assert.add('isFunction', function(actual) {
+ return typeof actual === 'function'
+ })
+ assert.add('isTrue', function(actual) {
+ return actual === true
+ })
+ assert.add('isFalse', function(actual) {
+ return actual === false
+ })
+ assert.add('isString', function(actual) {
+ return typeof actual === 'string'
+ })
+ assert.add('isBoolean', function(actual) {
+ return typeof actual === 'boolean'
+ })
+ assert.add('isNumber', function(actual) {
+ return typeof actual === 'number' && !isNaN(actual)
+ })
+ assert.add('isArray', isArray)
+ assert.add('isElement', isElement)
+
}(this)
View
2  tests/tests.html
@@ -12,4 +12,4 @@
<!-- external script file, allows for headless testing -->
<script src="tests.js"></script>
</body>
-</html>
+</html>
View
471 tests/tests.js
@@ -1,7 +1,7 @@
if (typeof module !== 'undefined' && module.exports) {
var sinktest = require('../src/sink')
- , sink = sinktest.sink
- , start = sinktest.start;
+ sink = sinktest.sink
+ start = sinktest.start
}
sink('first pass', function (test, ok, before, after) {
@@ -71,13 +71,29 @@ if (typeof module !== 'undefined' && module.exports) {
});
}
-sink('timeout tests (takes 20 seconds)', function (test, ok, before, after, assert) {
+sink('async complete() callback style', function (test, ok, before, after, assert) {
+ test('should not need count', function (complete) {
+ ok(typeof complete == 'function', 'test function argument is a callback')
+ complete()
+ })
- before(function () {
- sink.timeout = false
+ test('should not allow assert/ok-less test (SHOULD FAIL)', function (complete) {
+ complete()
+ })
+
+ test('should work async (3 checks)', function (complete) {
+ setTimeout(function () {
+ ok(true, 'ok() at 500ms delay')
+ ok(true, 'nothing to see here')
+ assert(true, true, 'meaningless assert')
+ complete()
+ }, 500)
})
+})
- test('should be able to assert stuff. this shows fail', 1, function () {
+sink('asserts', function (test, ok, before, after, assert) {
+
+ test('should be able to assert stuff (SOULD FAIL)', 1, function () {
assert(1, 6, 'should have same numbers')
})
@@ -85,6 +101,447 @@ sink('timeout tests (takes 20 seconds)', function (test, ok, before, after, asse
assert(2, 2, 'should have same numbers')
})
+ var exports = {}
+ assert.throws = function(fn) {
+ assert.__negateNext = true
+ return fn()
+ }
+
+// the following is copied straight from the CommonJS Unit-Testing Assertions module:
+// https://github.com/commonjs/commonjs/blob/master/tests/unit-testing/1.0/program.js
+// (commit) https://github.com/commonjs/commonjs/commit/8203f29d858d4d2adbd2bb911949fac7459ac264
+/*************** START COMMONJS STUFF ********************/
+
+// From Node.js test/mjsunit/test-assert.js
+// Felix Geisendörfer (felixge), backported from NodeJS
+// Karl Guertin (greyrest), backported from NodeJS
+// Kris Kowal (kriskowal), conversion to CommonJS
+
+// strangely meta, no?
+
+function makeBlock(f) {
+ var args = Array.prototype.slice.call(arguments,1);
+ return function(){
+ return f.apply(this, args);
+ }
+}
+
+/* @rvagg: not supported
+exports['test AssertionError instanceof Error'] = function () {
+ assert.ok(new assert.AssertionError({}) instanceof Error);
+};
+*/
+
+exports['test ok false'] = function () {
+ assert['throws'](makeBlock(assert.ok, false), assert.AssertionError);
+};
+
+exports['test ok(true)'] = makeBlock(assert.ok, true);
+exports['test ok("test")'] = makeBlock(assert.ok, "test");
+exports['test equal true false'] = function () {
+ assert['throws'](makeBlock(assert.equal, true, false), assert.AssertionError, 'equal');
+};
+
+exports['test equal null null'] = makeBlock(assert.equal, null, null);
+exports['test equal undefined undefined'] = makeBlock(assert.equal, undefined, undefined);
+exports['test equal null undefined'] = makeBlock(assert.equal, null, undefined);
+exports['test equal 2 "2"'] = makeBlock(assert.equal, 2, "2");
+exports['test equal "2" 2'] = makeBlock(assert.equal, "2", 2);
+exports['test equal true true'] = makeBlock(assert.equal, true, true);
+exports['test notEqual true false'] = makeBlock(assert.notEqual, true, false);
+exports['test notEqual true true'] = function () {
+ assert['throws'](makeBlock(assert.notEqual, true, true), assert.AssertionError, 'notEqual');
+};
+exports['test strictEqual 2 "2"'] = function () {
+ assert['throws'](makeBlock(assert.strictEqual, 2, "2"), assert.AssertionError, 'strictEqual');
+};
+exports['test strictEqual null undefined'] = function () {
+ assert['throws'](makeBlock(assert.strictEqual, null, undefined), assert.AssertionError, 'strictEqual');
+};
+exports['test notStrictEqual 2 "2"'] = makeBlock(assert.notStrictEqual, 2, "2");
+
+//deepEquals
+
+//7.2
+exports['test 7.2 deepEqual date'] = makeBlock(assert.deepEqual, new Date(2000,3,14), new Date(2000,3,14));
+exports['test 7.2 deepEqual date negative'] = function () {
+ assert['throws'](makeBlock(assert.deepEqual, new Date(), new Date(2000,3,14)), assert.AssertionError, 'deepEqual date');
+};
+
+//7.3
+exports['test 7.3 deepEqual 4 "4"'] = makeBlock(assert.deepEqual, 4, "4");
+exports['test 7.3 deepEqual "4" 4'] = makeBlock(assert.deepEqual, "4", 4);
+exports['test 7.3 deepEqual true 1'] = makeBlock(assert.deepEqual, true, 1);
+exports['test 7.3 deepEqual 4 "5"'] = function () {
+ assert['throws'](makeBlock(assert.deepEqual, 4, "5"));
+};
+
+//7.4
+// having the same number of owned properties && the same set of keys
+exports['test 7.4 deepEqual {a:4} {a:4}'] = makeBlock(assert.deepEqual, {a:4}, {a:4});
+exports['test 7.4 deepEqual {a:4,b:"2"} {a:4,b:"2"}'] = makeBlock(assert.deepEqual, {a:4,b:"2"}, {a:4,b:"2"});
+exports['test 7.4 deepEqual [4] ["4"]'] = makeBlock(assert.deepEqual, [4], ["4"]);
+exports['test 7.4 deepEqual {a:4} {a:4,b:true}'] = function () {
+ assert['throws'](makeBlock(assert.deepEqual, {a:4}, {a:4,b:true}), assert.AssertionError);
+};
+
+exports['test deepEqual ["a"], {0:"a"}'] = makeBlock(assert.deepEqual, ["a"], {0:"a"});
+//(although not necessarily the same order),
+exports['test deepEqual {a:4,b:"1"} {b:"1",a:4}'] = makeBlock(assert.deepEqual, {a:4,b:"1"}, {b:"1",a:4});
+
+exports['test deepEqual arrays with non-numeric properties'] = function () {
+ var a1 = [1,2,3];
+ var a2 = [1,2,3];
+ a1.a = "test";
+ a1.b = true;
+ a2.b = true;
+ a2.a = "test"
+ //@rvagg Object.keys() not universal: assert['throws'](makeBlock(assert.deepEqual, Object.keys(a1), Object.keys(a2)), assert.AssertionError);
+ makeBlock(assert.deepEqual, a1, a2)
+ () //@rvagg, execute this fn
+};
+
+exports['test deepEqual identical prototype'] = function () {
+ // having an identical prototype property
+ var nbRoot = {
+ toString: function(){return this.first+' '+this.last;}
+ }
+ var nameBuilder = function(first,last){
+ this.first = first;
+ this.last = last;
+ return this;
+ }
+ nameBuilder.prototype = nbRoot;
+ var nameBuilder2 = function(first,last){
+ this.first = first;
+ this.last = last;
+ return this;
+ }
+ nameBuilder2.prototype = nbRoot;
+ var nb1 = new nameBuilder('Ryan', 'Dahl');
+ var nb2 = new nameBuilder2('Ryan','Dahl');
+
+ assert.deepEqual(nb1, nb2);
+
+ /* @rvagg: IMO this is garbage and conflicts with the '["a"], {0:"a"}' test above
+ nameBuilder2.prototype = Object;
+ nb2 = new nameBuilder2('Ryan','Dahl');
+ assert['throws'](makeBlock(assert.deepEqual, nb1, nb2), assert.AssertionError);
+ */
+};
+
+exports['test deepEqual "a" {}'] = function () {
+ assert['throws'](makeBlock(assert.deepEqual, 'a', {}), assert.AssertionError);
+};
+
+exports['test deepEqual "" ""'] = function () {
+ assert.deepEqual("", "");
+};
+
+exports['test deepEqual "" [""]'] = function () {
+ assert['throws'](makeBlock(assert.deepEqual, '', ['']), assert.AssertionError);
+};
+
+exports['test deepEqual [""] [""]'] = function () {
+ assert.deepEqual([""], [""]);
+};
+
+/* @rvagg: not supported
+exports['test throw AssertionError'] = function () {
+
+ //Testing the throwing
+ function thrower(errorConstructor){
+ throw new errorConstructor('test');
+ }
+ var aethrow = makeBlock(thrower, assert.AssertionError);
+ var aethrow = makeBlock(thrower, assert.AssertionError);
+ //the basic calls work
+ assert['throws'](makeBlock(thrower, assert.AssertionError), assert.AssertionError, 'message');
+ assert['throws'](makeBlock(thrower, assert.AssertionError), assert.AssertionError);
+ assert['throws'](makeBlock(thrower, assert.AssertionError));
+ //if not passing an error, catch all.
+ assert['throws'](makeBlock(thrower, TypeError));
+ //when passing a type, only catch errors of the appropriate type
+ var threw = false;
+ try {
+ assert['throws'](makeBlock(thrower, TypeError), assert.AssertionError);
+ } catch (e) {
+ threw = true;
+ assert.ok(e instanceof TypeError, 'type');
+ }
+ assert.ok(threw, 'assert.throws with an explicit error is eating extra errors', assert.AssertionError);
+ threw = false;
+
+};
+*/
+
+/*************** END COMMONJS STUFF ********************/
+
+ var t, c
+ for (t in exports) {
+ if (exports.hasOwnProperty(t)) {
+ test('CommonJS Unit Testing/1.0: ' + t.replace(/^test /, ''), 1, exports[t])
+ }
+ }
+
+ // additional custom assert types
+
+ test('assert.typeOf()', 6, function () {
+ assert.typeOf('a string', 'string', 'should be a string')
+ assert.__negateNext = true
+ assert.typeOf('a string', 'object', 'should not be an object')
+ assert.typeOf({one:1}, 'object', 'should be an array')
+ assert.typeOf(100, 'number', 'should be a number')
+ assert.__negateNext = true
+ assert.typeOf(100, 'string', 'should not be a string')
+ assert.typeOf(1.1, 'number', 'should be a number')
+ })
+
+ test('assert.notTypeOf()', 6, function () {
+ assert.__negateNext = true
+ assert.notTypeOf('a string', 'string', 'should be a string')
+ assert.notTypeOf('a string', 'object', 'should not be an object')
+ assert.__negateNext = true
+ assert.notTypeOf({one:1}, 'object', 'should be an array')
+ assert.__negateNext = true
+ assert.notTypeOf(100, 'number', 'should be a number')
+ assert.notTypeOf(100, 'string', 'should not be a string')
+ assert.__negateNext = true
+ assert.notTypeOf(1.1, 'number', 'should be a number')
+ })
+
+ test('assert.isDefined()', 6, function () {
+ assert.isDefined('', 'should be defined')
+ assert.isDefined(1, 'should be defined')
+ assert.isDefined({}, 'should be defined')
+ assert.isDefined([], 'should be defined')
+ assert.isDefined(null, 'should be defined')
+ assert.__negateNext = true
+ assert.isDefined(undefined, 'should not be defined')
+ })
+
+ test('assert.isUndefined()', 6, function () {
+ assert.__negateNext = true
+ assert.isUndefined('', 'should not be undefined')
+ assert.__negateNext = true
+ assert.isUndefined(1, 'should not be undefined')
+ assert.__negateNext = true
+ assert.isUndefined({}, 'should not be undefined')
+ assert.__negateNext = true
+ assert.isUndefined([], 'should not be undefined')
+ assert.__negateNext = true
+ assert.isUndefined(null, 'should not be undefined')
+ assert.isUndefined(undefined, 'should be undefined')
+ })
+
+ test('assert.isNull()', 6, function () {
+ assert.__negateNext = true
+ assert.isNull('', 'should not be null')
+ assert.__negateNext = true
+ assert.isNull(1, 'should not be null')
+ assert.__negateNext = true
+ assert.isNull({}, 'should not be null')
+ assert.__negateNext = true
+ assert.isNull([], 'should not be null')
+ assert.isNull(null, 'should be null')
+ assert.__negateNext = true
+ assert.isNull(undefined, 'should not be null')
+ })
+
+ test('assert.isNotNull()', 6, function () {
+ assert.isNotNull('', 'should not be null')
+ assert.isNotNull(1, 'should not be null')
+ assert.isNotNull({}, 'should not be null')
+ assert.isNotNull([], 'should not be null')
+ assert.__negateNext = true
+ assert.isNotNull(null, 'should be null')
+ assert.isNotNull(undefined, 'should not be null')
+ })
+
+ test('assert.isObject()', 6, function () {
+ assert.isObject({}, 'should be an object')
+ assert.isObject([], 'should be an object')
+ assert.__negateNext = true
+ assert.isObject(1, 'should not be an object')
+ assert.__negateNext = true
+ assert.isObject('a string', 'should not be an object')
+ assert.__negateNext = true
+ assert.isObject(null, 'should not be an object')
+ assert.__negateNext = true
+ assert.isObject(undefined, 'should not be an object')
+ })
+
+ test('assert.isFunction()', 8, function () {
+ assert.isFunction(function() {}, 'should be a function')
+ assert.isFunction(assert, 'should be a function')
+ assert.__negateNext = true
+ assert.isFunction({}, 'should not be a function')
+ assert.__negateNext = true
+ assert.isFunction([], 'should not be a function')
+ assert.__negateNext = true
+ assert.isFunction(1, 'should not be a function')
+ assert.__negateNext = true
+ assert.isFunction('a string', 'should not be a function')
+ assert.__negateNext = true
+ assert.isFunction(null, 'should not be a function')
+ assert.__negateNext = true
+ assert.isFunction(undefined, 'should not be a function')
+ })
+
+ test('assert.isTrue()', 10, function () {
+ assert.isTrue(true, 'should be true')
+ assert.__negateNext = true
+ assert.isTrue(false, 'should not be true')
+ assert.__negateNext = true
+ assert.isTrue(null, 'should not be true')
+ assert.__negateNext = true
+ assert.isTrue(undefined, 'should not be true')
+ assert.__negateNext = true
+ assert.isTrue('', 'should not be true')
+ assert.__negateNext = true
+ assert.isTrue('a string', 'should not be true')
+ assert.__negateNext = true
+ assert.isTrue(1, 'should not be true')
+ assert.__negateNext = true
+ assert.isTrue(0, 'should not be true')
+ assert.__negateNext = true
+ assert.isTrue({}, 'should not be true')
+ assert.__negateNext = true
+ assert.isTrue([], 'should not be true')
+ })
+
+ test('assert.isFalse()', 10, function () {
+ assert.isFalse(false, 'should be false')
+ assert.__negateNext = true
+ assert.isFalse(true, 'should not be false')
+ assert.__negateNext = true
+ assert.isFalse(null, 'should not be false')
+ assert.__negateNext = true
+ assert.isFalse(undefined, 'should not be false')
+ assert.__negateNext = true
+ assert.isFalse('', 'should not be false')
+ assert.__negateNext = true
+ assert.isFalse('a string', 'should not be false')
+ assert.__negateNext = true
+ assert.isFalse(1, 'should not be false')
+ assert.__negateNext = true
+ assert.isFalse(0, 'should not be false')
+ assert.__negateNext = true
+ assert.isFalse({}, 'should not be false')
+ assert.__negateNext = true
+ assert.isFalse([], 'should not be false')
+ })
+
+ test('assert.isString()', 10, function () {
+ assert.isString('', 'should be a string')
+ assert.isString('a string', 'should be a string')
+ assert.__negateNext = true
+ assert.isString(false, 'should not be a string')
+ assert.__negateNext = true
+ assert.isString(true, 'should not be a string')
+ assert.__negateNext = true
+ assert.isString(null, 'should not be a string')
+ assert.__negateNext = true
+ assert.isString(undefined, 'should not be a string')
+ assert.__negateNext = true
+ assert.isString(1, 'should not be a string')
+ assert.__negateNext = true
+ assert.isString(0, 'should not be a string')
+ assert.__negateNext = true
+ assert.isString({}, 'should not be a string')
+ assert.__negateNext = true
+ assert.isString([], 'should not be a string')
+ })
+
+ test('assert.isBoolean()', 10, function () {
+ assert.isBoolean(false, 'should be a boolean')
+ assert.isBoolean(true, 'should be a boolean')
+ assert.__negateNext = true
+ assert.isBoolean('', 'should be a boolean')
+ assert.__negateNext = true
+ assert.isBoolean('a boolean', 'should not be a string')
+ assert.__negateNext = true
+ assert.isBoolean(null, 'should not be a boolean')
+ assert.__negateNext = true
+ assert.isBoolean(undefined, 'should not be a boolean')
+ assert.__negateNext = true
+ assert.isBoolean(1, 'should not be a boolean')
+ assert.__negateNext = true
+ assert.isBoolean(0, 'should not be a boolean')
+ assert.__negateNext = true
+ assert.isBoolean({}, 'should not be a boolean')
+ assert.__negateNext = true
+ assert.isBoolean([], 'should not be a boolean')
+ })
+
+ test('assert.isNumber()', 12, function () {
+ assert.isNumber(1, 'should be a number')
+ assert.isNumber(0, 'should be a number')
+ assert.isNumber(-1.1, 'should be a number')
+ assert.isNumber(10000.1010101, 'should be a number')
+ assert.__negateNext = true
+ assert.isNumber('', 'should be a number')
+ assert.__negateNext = true
+ assert.isNumber('a number', 'should not be a string')
+ assert.__negateNext = true
+ assert.isNumber(false, 'should not be a number')
+ assert.__negateNext = true
+ assert.isNumber(true, 'should not be a number')
+ assert.__negateNext = true
+ assert.isNumber(null, 'should not be a number')
+ assert.__negateNext = true
+ assert.isNumber(undefined, 'should not be a number')
+ assert.__negateNext = true
+ assert.isNumber({}, 'should not be a number')
+ assert.__negateNext = true
+ assert.isNumber([], 'should not be a number')
+ })
+
+ test('assert.isArray()', 12, function () {
+ assert.isArray([], 'should be an array')
+ assert.isArray([1,2,3], 'should be an array')
+ assert.isArray(new Array(), 'should be an array')
+ assert.__negateNext = true
+ assert.isArray('', 'should not be an array')
+ assert.__negateNext = true
+ assert.isArray('an array', 'should not be an array')
+ assert.__negateNext = true
+ assert.isArray(false, 'should not be an array')
+ assert.__negateNext = true
+ assert.isArray(true, 'should not be an array')
+ assert.__negateNext = true
+ assert.isArray(null, 'should not be an array')
+ assert.__negateNext = true
+ assert.isArray(undefined, 'should not be an array')
+ assert.__negateNext = true
+ assert.isArray(1, 'should not be an array')
+ assert.__negateNext = true
+ assert.isArray(0, 'should not be an array')
+ assert.__negateNext = true
+ assert.isArray({}, 'should not be an array')
+ })
+
+ test('single argument custom assert', 2, function () {
+ assert.add('isHairy', function(actual) { return 'big hairy monster' === actual })
+ assert.isHairy('big hairy monster', 'should be a big hairy monster')
+ assert.__negateNext = true
+ assert.isHairy('this is not a big hairy monster', 'should not be a big hairy monster')
+ })
+
+ test('dual argument custom assert', 2, function () {
+ assert.add('matchesRegex', function(actual, expected) { return expected.test(actual) })
+ assert.matchesRegex('does this match?', / this /, 'should match the regex')
+ assert.__negateNext = true
+ assert.matchesRegex('does this match?', / NO MATCH FOR YOU /, 'should not match the regex')
+ })
+})
+
+sink('timeout tests (takes 20 seconds)', function (test, ok, before, after, assert) {
+
+ before(function () {
+ sink.timeout = false
+ })
+
test('should pass a test thing or two', 1, function () {
setTimeout(function () {
ok(true, 'timeout successfully nulled!')
@@ -93,4 +550,4 @@ sink('timeout tests (takes 20 seconds)', function (test, ok, before, after, asse
})
-start()
+start()

No commit comments for this range

Something went wrong with that request. Please try again.