2

I'm trying to port some Jasmine tests from javascript to LiveScript. One of Jasmine's functions is it. Here's an example:

(function(){
  describe("The selling page", function() {
    // bla bla
    it("should display cards.", function() {
        expect(selectedCards.count()).toEqual(1);
    });
});

So, I tried this in LiveScript:

do !->
  describe "the selling page " !->
   it "should display cards" !->
       expect (selectedCards.count()).toEqual("")

Which compiles to this:

// Generated by LiveScript 1.3.1
(function(){
   describe("the selling page ", function(it){ // <--- note the "it"
     it("should display cards", function(){
     expect(browser.getTitle().toEqual(""));
});
});
})();

You notice that the second function takes the "it" as an argument. I didn't find the livescript doc about this but I understand it's a feature (if I replace the it function by something else it's all fine. That makes me confident I'm not partially applying a function).

However, I need the it function and I don't want it as an argument. How can I write this snippet then ? Thanks !

Ehvince
  • 17,274
  • 7
  • 58
  • 79

2 Answers2

3

You should use (...) in describe to avoid adding extra params

Like that:

do !->
  describe "the selling page", (...) !->
   it "should display cards" !->
       expect (selectedCards.count()).toEqual("")
Monomachus
  • 1,448
  • 2
  • 13
  • 22
  • That works, thanks. mmh… so we don't use splats here to "call the function with the arguments of the current function". Are we doing destructuring of arguments here ? – Ehvince Oct 16 '15 at 18:46
  • 1
    @Ehvince it's an anonymous splat, which doesn't bind anything – Ven Nov 03 '15 at 17:00
1

If you don't mind aliasing it for something else, you can also do this:

that = it

do !->
  describe "the selling page " !->
   that "should display cards" !->
       expect selectedCards.count! .to-equal ''

When it is not in a function, it is treated as global it.