UNPKG

siesta-lite

Version:

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

87 lines (60 loc) 2.3 kB
describe("My test suite", function (t) { t.beforeEach(function(){ // Do some setup code code here }); t.afterEach(function(){ // Do some cleanup code code here }); // the difference between `describe` and `it` is purely semantical - both are just "sub-tests" in Siesta terms t.describe("Both assertion types should work", function (t) { t.it("Perl-style assertions", 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.it("Expectations should work", function (t) { t.expect(1).toBe(1) t.expect(1).not.toBe(2) t.expect([]).toEqual([]) t.expect([]).not.toEqual({}) t.expect([]).not.toBeNull() t.expect(null).toBeNull() t.expect(NaN).toBeNaN() t.expect(1).toBeDefined() t.expect(undefined).toBeUndefined() t.expect("Foo").toMatch(/foo/i) t.expect("Bar").not.toMatch(/foo/i) t.expect([ 1 ]).toContain(1) t.expect([ 1 ]).not.toContain(2) t.expect("Foo").toContain("oo") t.expect("Bar").not.toContain("oo") t.expect(1).toBeCloseTo(1.01, 1) t.expect(function () { throw new Error("exception"); }).toThrow() t.expect(function () { }).not.toThrow() // this is a regular Siesta method t.waitFor(10, function () {}) }) }) t.describe("Nested Describe", function (t) { t.it("Nested it", function (t) { }) }) })