Nested describes are useful when you want to describe similar behavior between specs. Suppose we want the following two new acceptance criteria:
- Given an investment, when its stock share price valorizes, it should have a positive return on investment (ROI)
- Given an investment, when its stock share price valorizes, it should be a good investment
Both these criteria share the same behavior when the investment's stock share price valorizes.
To translate this into Jasmine, you can nest a call to the
describe function inside the existing one in the
InvestmentSpec.js file (I removed the rest of the code for the purpose of demonstration; it is still there):
describe("Investment", function() describe("when its stock share price valorizes", ...