What's the meaning of "it()" in Jasmine?
it('is really much more simple than you think)
The it()
syntax it is used to tell Jasmine what it('should happen in your test')
Jasmine is a testing framework for behavior driven development. And it function's purpose is to test a behavior of your code.
It takes a string that explains expected behavior and a function that tests it.
it("should be 4 when I multiply 2 with 2", function() {
expect(2 * 2).toBe(4);
});
It's not an abbreviation, it's just the word it
.
This allows for writing very expressive test cases in jasmine, and if you follow the scheme has very readable output.
Example:
describe("My object", function () {
it("can calculate 3+4", function () {
expect(myObject.add(3, 4)).toBe(7);
}
});
Then, if that test fails, the output will be like
Test failed: My object can calculate 3+4
Message:
Expected 6.99999 to equal 7
As you can see, this imaginary function suffers from some rounding error. But the point is that the resulting output is very readable and expressive, and the code is too.
The basic scheme in the code is: You describe
the unit that will be tested, and then test it
s various functions and states.