Very often, we reuse pieces of code across different scenarios. This is due to functionality dependencies among scenarios, preconditions, or some other requirements such as initialization/declaration of application/system variables or objects. This improves code redundancy and maintainability.
Generally, to avoid code duplication (across scenarios/Jasmine specs) and increase code reusability and readability, we use setup and teardown functions. Jasmine provides two global functions (that is,
afterEach) corresponding to setup and teardown functions. We can initialize variables and write common code and preconditions under the
beforeEach function. Similarly, the
afterEach function ...