Async callback within beforeEach

337 views
Skip to first unread message

Phil Cockfield

unread,
Feb 14, 2011, 8:41:25 PM2/14/11
to Jasmine
I got a situation where I have some setup to do in a beforeEach, but
some of that setup involved an async call.

How do I block the beforeEach until the async operation is complete?

I can't find any comment on this since 2009, here:
http://groups.google.com/group/jasmine-js/browse_thread/thread/84d49f93d21265d/3a0058b90a040e24?lnk=gst&q=beforeeach+async#3a0058b90a040e24

---

Using 'runs' seems to worsen the issue (which means I may not be
understanding 'runs' properly). I'd like not to have to put a Wait
inside a beforeEach as that will slow things down badly.

Thanks everyone.

Davis Frank

unread,
Feb 14, 2011, 11:34:23 PM2/14/11
to jasmi...@googlegroups.com
Can you post a sample?

In general, I'd expect a spec that required an async call to do it in a runs block at the top of the it block. Yes, that might lead to less DRY specs.

We never resolved the issue you mention from that thread.

--dwf



--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To post to this group, send email to jasmi...@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.


Phil Cockfield

unread,
Feb 15, 2011, 12:49:02 PM2/15/11
to jasmi...@googlegroups.com
Sure - what I'm doing is using 'require.js' [ http://requirejs.org/ ] to do script loading, and so I'm trying getting it to resolve all the script into the page before the test runs.

I think this is a more accurate testing situation (rather than have the Jasmine YML find and load all JS files automatically) because it ensure what I'm testing was setup the way it will actually run in production.  In fact, not loading things this way causes errors anyhow when the JS files are spun up independently by Jasmine, as they aren't expecting all to be just loaded into the page - so not only is this better (I think), it's kind of necessary.

So, the call in the beforeEach would be something like this:

beforeEach(function() {

  // Block here until require has finished.
  require(['module1', 'module2'], function(module1, module2) {

    // Done now .. unblock program flow so Jasmine can
    // move on to executing the test.

  })
});

I thought maybe a runs() closure would do the trick - but it doesn't seem to have an effect, and I may be missing the point of runs.  It doesn't seem to block execution until it's completed ... should it?

Is what I'm saying crazy .... am I just approaching this wrong?  
Thanks!

Freewind

unread,
May 10, 2012, 12:38:13 AM5/10/12
to jasmi...@googlegroups.com
I have exactly the same question. Someone has a good solution?
To unsubscribe from this group, send email to jasmine-js+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To post to this group, send email to jasmi...@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+unsubscribe@googlegroups.com.

Davis W. Frank

unread,
May 10, 2012, 9:38:41 AM5/10/12
to jasmi...@googlegroups.com

Matt has a solution that should work for you.

We're pondering a great way to solve this problem in jasmine core, but we're not there yet.

--dwf



To view this discussion on the web visit https://groups.google.com/d/msg/jasmine-js/-/Nu24WhXY3kgJ.

To post to this group, send email to jasmi...@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.



--
thx,
--dwf

Reply all
Reply to author
Forward
0 new messages