Professional Documents
Culture Documents
Test Tool Presentation
Test Tool Presentation
afterEach(function() {
foo = 0;
});
beforeAll(function() {
foo = 1;
});
afterAll(function() {
foo = 0;
});
});
Jasmine Matchers
• MATCHER PURPOSE
• toBe() passed if the actual value is of the same type and value as that of the expected value. It compares with === operator
• toEqual() works for simple literals and variables;
• toMatch() to check whether a value matches a string or a regular expression
• toBeDefined() to ensure that a property or a value is defined
• toBeUndefined() to ensure that a property or a value is undefined
• toBeNull() to ensure that a property or a value is null.
• toBeTruthy() to ensure that a property or a value is true
• ToBeFalsy() to ensure that a property or a value is false
• toContain() to check whether a string or array contains a substring or an item.
• toBeLessThan() for mathematical comparisons of less than
• toBeGreaterThan() for mathematical comparisons of greater than
• toBeCloseTo() for precision math comparison
• toThrow() for testing if a function throws an exception
• toThrowError() for testing a specific thrown exception
• Use not for negation
Jasmine Spies
describe("MathUtils", //Test for sum operation
function() { it("should be able to calculate sum of 3
and 5", function() {
var calc; //call any method
calc.sum(3,5);
beforeEach(function() {
//verify it got executed
calc = new MathUtils();
expect(calc.sum).toHaveBeenCalled();
spyOn(calc, 'sum');
expect(calc.sum).toHaveBeenCalledWith(3,5)
}); ;
});