siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
57 lines (41 loc) • 2.05 kB
JavaScript
StartTest(function (t) {
t.todo('Need handle incorrect types', function (todo) {
var summator = function (a, b) { return a + b }
todo.is(summator(1, 1), 2, 'Correct sum for 1 + 1')
todo.is(summator(1, 10), 11, 'Correct sum for 1 + 10')
// instead of `todo` here, you can use `t` - then later you can
// just rename the `todo` to `it`
todo.throwsOk(function () {
summator([], {})
}, 'Error', 'Throws exception for incorrect types')
// a special-case - need to auto-cast strings to numbers
todo.is(summator("1.1", "2.1"), 2.3, 'Correct auto-casting strings to number #1')
todo.is(summator("1.1", 2.1), 2.3, 'Correct auto-casting strings to number #2')
todo.is(summator(1.1, "2.1"), 2.3, 'Correct auto-casting strings to number #3')
// sometimes they actually start to pass
todo.is(summator(0, 1), 1, 'Sometimes they actually start to pass')
})
t.todo("Ok to fail in this sub test", function (t) {
t.ok(0, '0 is not ok')
t.ok('', 'Empty string is not ok')
t.is({}, {}, '{} is not {}')
t.isnt(1, 1, "1 is 1")
t.isStrict(null, undefined, 'Null is (==) undefined')
t.isntStrict(null, null, 'Null is === null')
t.like('Yo', /foo/i, '"Yoda" doesn\'t match /foo/i')
t.unlike('Yo', /yo/i, '"Yo" match "yo"')
t.unlike('Yoda', 'Yo', '"Yoda" contains "Yo"')
t.throwsOk(function () {
throw "yo"
}, /foo/, 'Exception thrown, but its not "foo"')
t.livesOk(function () {
throw "yo"
}, 'Exception not thrown')
t.isDeeply({ a : 1, b : 2 }, [ { c: 3 } ], 'JSON structures are different')
t.isDeeplyStrict({ a : 1, b : 2 }, { a : '1', b : 2 }, '`isDeeplyStrict` requires exact match (===)');
})
// You can also snooze some test till certain time
t.snooze(new Date(2050, 3, 4), function (t) {
t.is(1, 2, "We'll look into this one after the release");
})
});