March 2013
Intermediate to advanced
52 pages
51m
English
describe("colors", function() {
describe("red", function() {
var red;
beforeEach(function() {
red = new Color("red");
});
afterEach(function() {
red = null;
});
it("has the correct value", function() {
expect(red.hex).toEqual("FF0000");
});
it("makes orange when mixed with yellow", function() {
var yellow = new Color("yellow");
var orange = new Color("orange");
expect(red.mix(yellow)).toEqual(orange);
});
});
});toEqual checks for equality, not necessarily the same object.
toBe checks if two objects are the same.
toBeTruthy checks if a value is truthy (not just true).
toBeFalsy checks if a value is falsy (not just false).
toContain checks if a value is inside another.
toBeDefined checks if a value is defined.
toBeUndefined checks if a value is undefined.
toBeNull checks if a value is null.
toBeNaN checks if a value is NaN.
toBeCloseTo checks decimal proximity.
toMatch checks if a value matches a given regular expression.
toThrow checks if a function throws an error.
.not inverts the meaning of the following matcher.
false
0
""
undefined (note that the variable undefined isn’t always undefined!)
null
NaN
The following are words that you shouldn’t use in your code so that you don’t cause conflicts with Jasmine:
jasmine (and everything in its namespace)
describe
it
expect
beforeEach
afterEach
Read now
Unlock full access