Setup and teardown
It's important to understand that the describe
and it
global functions will not only contain specifications and expectations respectively. It's always necessary to add some more code to set up the complete and working tests, for example, code needed to implement all the objects involved in what we are verifying and all the method calls that trigger the specifications events that we need to stress on.
There are two Jasmine global functions that help setting up a proper test execution environment: beforeEach
and afterEach
. Like every other unit testing framework, Jasmine provides these two functions to set up and teardown a specification context. In the beforeEach
function, we have to write all the code needed to create and initialize all the objects that we need to execute a single specification. The afterEach
function is used to reset all these objects. They both take a function as a single argument, which will be executed by the spec runner.
Jasmine calls these...