Using Jasmine 2, I want to:
- compute a value in a beforeAll/beforeEach block
- access it in the it / nested describe block
so far easy: set a var and use it [OUT below]. It will have right values by the time it runs.
- extract test cases / nested suite into a function.
That's harder, especially with nested suites - nested describe body is executed immediately, before any beforeEach/All blocks. Trying to passing the outer variable would pass the initial undefined/null [IN1 below]. => Passing a closure to get current value of the variable works if you only call it from it blocks [IN2 below].
Using Mocha, the exact same thing happens - just replace beforeAll->`before`, afterAll->`after`.