before/after on suites?

1,281 views
Skip to first unread message

robertj

unread,
Nov 14, 2011, 9:28:40 AM11/14/11
to jasmi...@googlegroups.com
Hi,

I'd like to define a before and after code block on a suite. Is this possible?

describe "many tests", ->
  before ->
    console.log "this will run once for all the following specs"

  it "does something", ->
    ..
  
  it "does something else", - >
    ..

Best regards

Robert

robertj

unread,
Nov 14, 2011, 9:32:28 AM11/14/11
to jasmi...@googlegroups.com
OK, gonna answer this myself as the most useless question ever.

of course I can. I simply put my code between the describe and the it. Everything will be executed.

describe "many tests", ->

Jamison Dance

unread,
Nov 14, 2011, 10:31:28 AM11/14/11
to jasmi...@googlegroups.com
One gotcha on this is if you are testing stuff with callbacks. If you
want code to run after your callbacks, you would need to somehow
synchronize your callbacks with something like
https://github.com/coolaj86/futures, or put some `waits()` before your
code you want to run after.

> --
> You received this message because you are subscribed to the Google Groups
> "Jasmine" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/jasmine-js/-/QVWRduoALukJ.
> 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.
>

robertj

unread,
Nov 14, 2011, 2:40:06 PM11/14/11
to jasmi...@googlegroups.com
thanks for the hint

Rajan Agaskar

unread,
Nov 15, 2011, 12:07:45 PM11/15/11
to jasmi...@googlegroups.com
Careful here, code in the describe scope will run at suite parse time, not suite execution time. IE, it will run before any suites start executing. 

--
Reply all
Reply to author
Forward
0 new messages