Good afternoon all,
I'm looking for a feature in Jasmine that behaves like a "justBeforeEach", or a "prependBeforeEach". The primary motivation for this behavior is to allow spec context to change the setup for the object under test while drying code up. Consider the following implementation:
describe('a feature', function() {
var settings;
beforeEach(function() {
DoSomeSetupWork(settings)
});
describe('when foo is bar', function() {
beforeEach( function() {
settings.foo = 'bar';
});
it('...', function() {});
});
describe('when foo is baz', function() {
beforeEach( function() {
settings.foo = 'baz';
});
it('...', function() {});
});
});
The order in which the callbacks run mean DoSomeSetupWork will always run with undefined in this case. Two possible solutions:
- prepend a function to run at the front of the callback chain.
- maintain a separate callback list for justBeforeEach that runs after all beforeEach declarations, but in order of their declarations.
My preference is for #2 of these two options.
I'm curious if a feature like this has previously been declined for inclusion in Jasmine, and if not is this a feature that would be desirable? I have reviewed the code responsible for these behaviors and think it is within my skill set to accomplish.
-Brian