unit-testing livescript with jasmine: just deal with 'it'

238 views
Skip to first unread message

Elizabeth Marston

unread,
Oct 28, 2013, 8:17:19 PM10/28/13
to lives...@googlegroups.com
Just in case someone else has run into this:

If you're doing unit tests with jasmine-node, you can use grunt and grunt-livescript to generate specfiles (unit test files) for jasmine-node. No surprises there! ...BUT there was a surprise almost immediately thereafter. Can you see the problem with the following? 

describe "Hello World" ->
  it "should be true" ->
   expect true
      .toBe true

As most of us probably know, 'it' in LS is an implicit variable defined in functions which do not stipulate a parameter. This parameter, when interpolated by the compiler, masks 'it' from the surrounding closure, rendering jasmine useless.

There's an obvious solution that o course took far too long to figure out. Simply declare an EXPLICIT parameter. You don't ever have to do anything with it, it just has to sop up what, if anything, gets passed at runtime.

describe "Hello World" (...devnull) ->  
  it "should be true" ->
   expect true
      .toBe true

In the future though, it would be nice if LiveScript compiled  'it' to __random-unique-varname rather than 'it'; what do you think, gkz?



Chia-liang Kao

unread,
Oct 29, 2013, 3:14:55 PM10/29/13
to lives...@googlegroups.com
Hi,

This is actually quite common, personally I prefer this ``it`` with cascade:

describe "Hello World" -> ``it``
  .. "should be true" ->
    expect true .toBe true
  .. "should be false" ->
    expect false .toBe false

clkao

Elizabeth Marston

unread,
Oct 29, 2013, 5:38:47 PM10/29/13
to lives...@googlegroups.com
Wow, thanks!

Albert Rodenius

unread,
Jul 8, 2014, 11:43:07 AM7/8/14
to lives...@googlegroups.com
Thanks to both of you, this just saved me a lot of frustration!

Wolf Flow

unread,
Jul 9, 2014, 5:59:27 AM7/9/14
to lives...@googlegroups.com
Hi all, and my favourite is:

specify = it

describe "Hello World" ->
  specify "should be true" ->
     expect true .toBe true

Matt Brennan

unread,
Aug 5, 2014, 5:41:56 AM8/5/14
to lives...@googlegroups.com
A slightly nicer way of silencing the implicit parameter is using void:

describe "Hello World" (void) ->  
  it "should be true" ->
   expect true
      .toBe true

Personally I prefer Mocha with the exports ui.
Reply all
Reply to author
Forward
0 new messages