UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

81 lines (57 loc) 2.25 kB
StartTest(t => { t.it("Ok assertions", t => { t.ok(true, 'True is ok') t.ok(1, '1 is ok') t.ok({}, '{} is ok') t.notOk(false, 'false is not ok') t.notOk(0, '0 is not ok') t.notOk(undefined, '`undefined` is not ok') }) t.it("Is assertions", t => { t.is(1, 1, '1 is 1') t.is(1, "1", '1 is "1"') t.is(null, undefined, 'null is undefined') t.isnt(1, 2, "1 isn't 2") }) t.it("Like assertions", t => { t.like('Yo', /yo/i, '"Yo" is like "yo"') t.like('Yoda', 'Yo', '"Yoda" contains "Yo"') t.like(__filename, /basic_assertions\.t\.js$/, 'Correct file name') }) t.it("Throws / lives assertions", t => { t.throwsOk(() => { throw "yo" }, /yo/, 'Exception thrown, and its "yo"') t.livesOk(() => { let a = 1 }, 'Exception not thrown') }) t.it("Deep comparison", t => { t.isDeeply({ a : 1, b : 2 }, { a : '1', b : 2 }, 'Correct') t.isDeeply({ a : 1, b : 2 }, { a : 1, b : 2 }, 'Correct') }) // wrapped with "todo" to prevent the assertions from failing the test t.todo("examples of failed assertions", 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(() => { throw "yo" }, /foo/, 'Exception thrown, but its not "foo"') t.livesOk(() => { 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 allow an assertion to fail temporarily to not forget it t.snooze(new Date(2050, 3, 4), t => { t.is(1, 2, "We'll look into this one after the release"); }) })