justBeforeEach implementation

33 views
Skip to first unread message

brian.ma...@terminus.com

unread,
May 15, 2017, 1:50:28 PM5/15/17
to Jasmine Dev
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:

  1. prepend a function to run at the front of the callback chain.
  2. 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

Gregg Van Hove

unread,
May 15, 2017, 4:49:42 PM5/15/17
to jasmine...@googlegroups.com
I don't think this is a feature that we really want in Jasmine. If you have similar, but slightly different setup, I would suggest you call `DoSomeSetupWork` directly in the child suites where they have all of the necessary information. This allows you to have the full context of what is being set up closer to the specs, so that when they fail unexpectedly, it is easier to figure out what the setup is.

-Gregg

--
You received this message because you are subscribed to the Google Groups "Jasmine Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js-dev+unsubscribe@googlegroups.com.
To post to this group, send email to jasmine-js-dev@googlegroups.com.
Visit this group at https://groups.google.com/group/jasmine-js-dev.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages