Using the "this" keyword
In Jasmine, we can also initialize and share the variables between beforeEach
, it
, and afterEach
using the this
keyword. In this recipe, we will see how the this
keyword can be used within the beforeEach
or afterEach
functions.
Getting ready
You will learn this recipe with the help of the previous recipe. For more information, refer to the previous recipe, Applying setup and teardown functions to the Jasmine test. In this recipe, we refactor three scenarios for a sales and inventory control system by initializing/putting together common code in the beforeEach
and afterEach
functions.
How to do it…
To apply the this
keyword to your Jasmine test, you need to perform the following steps:
- First, you need to create a spec file ( ...
Get Jasmine Cookbook 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.