Set up and tear down
Just like other frameworks, Jasmine also provides a way to set up and tear down. Jasmine provides global functions such as beforeEach
—called before each spec, afterEach
—called after each spec, beforeAll
—called only once before all specs are run, and afterAll
—called only once after all specs are done. Look at the following code to understand this:
describe("Setup and Teardown", function() { var count = 0; var velocity = 0; beforeEach(function() { velocity = 100; count++; console.log("Count is "+ count); }); afterEach(function() { velocity = 0; console.log("Some spec just finished and this function is called"); }); beforeAll(function(){ console.log("This is called only once, specs are about to run."); }); afterAll(function(){ console.log("All specs finished, time for cleanup"); }); it("Testing Velocity and reducing velocity", function() { expect(velocity).toEqual(100); velocity = 20; expect(velocity...