A setup allows us to set up test data and variables before each of the test specs are executed. This avoids having to repeat the same code and variables in each spec. This is equivalent to the @isTestsetup annotation in Apex.
A setup is defined using a beforeEach() function that takes a closure function as an argument.
//This will be called before running each spec beforeEach(function() { stringUtil = new StringUtils(); });
A teardown allows us to clean the variables before continuing. Jasmine provides an afterEach function for teardowns; look at the following sample code for the syntax. Note that it also takes a closure function as an argument.
afterEach(function() { console.log("afterEach"); });