Setup and teardown

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");    });

Get Learning Salesforce Lightning Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.