This is a draft cheat sheet. It is a work in progress and is not finished yet.
Jasmine test blockdescribe("A suite", function() {
describe("Optional subsection", function() {
beforeEach(function() {
// runs before every it(...) in the block
});
afterEach(function() {
// runs after every it(...) in the block
});
it("contains tests", function() {
// assert using matchers
expect(true).toBe(true);
});
});
});
|
Focused testsddescribe(block, function() { ... }) Run only tests in this block | iit(test, function() { ... }) Run only this test. Takes presedence over ddescribe(...) |
Skipped testsxdescribe( label, function(){ ... }) skip block | xit( label, function(){ ... }) skip test |
| | Matchersexpect(1).toBe(1); match with === | expect({a:1}).toEqual({a:1}); match simple literals and variables | expect("foo bar").toMatch(/bar/) match regular expressions | expect(foo).toBeDefined(); match against undefined | expect(bar).toBeUndefined(); identical to expect(bar).not.toBeDefined(); | expect(null).toBeNull(); match against null | expect(1).toBeTruthy(); | expect(0).toBeFalsy(); | expect(["foo", "bar"]).toContain("bar"); match an item in an Array | expect(1).toBeLessThan(2); | expect(2).toBeGreaterThan(1); | expect(1).toBeCloseTo(1.5, 1); | expect(function).toThrow(); expect(function() { throw 'error message';}).toThrow() |
| | |