2

我正在尝试将一些 Jasmine 测试从 javascript 移植到 LiveScript。Jasmine 的功能之一是it. 这是一个例子:

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

所以,我在 LiveScript 中尝试了这个:

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

编译为:

// 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(""));
});
});
})();

您注意到第二个函数将“it”作为参数。我没有找到关于此的 livescript 文档,但我了解它是一个功能(如果我用it其他东西替换该功能,那一切都很好。这让我确信我没有部分应用一个功能)。

但是,我需要这个it函数,我不希望它作为一个参数。那我怎么写这个片段呢?谢谢 !

4

2 回答 2

3

您应该在描述中使用 (...) 以避免添加额外的参数

像那样:

do !->
  describe "the selling page", (...) !->
   it "should display cards" !->
       expect (selectedCards.count()).toEqual("")
于 2015-10-16T18:29:16.147 回答
1

如果您不介意it为其他东西使用别名,您也可以这样做:

that = it

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

it不在函数中时,它被视为全局it

于 2016-10-27T17:38:33.113 回答