2

Jasmine 跳过了我所有的“it”测试,除了描述块中的最后一个测试——我在测试中使用了咖啡脚本,我相信这可能是原因。当我查看由我的 .coffee 测试创建的已编译 JS 时,我发现只有最后一个“it”测试前面有“return”这个词,这可能是跳过其余测试的原因。

我的问题是,我怎样才能让它“返回”所有测试?

编译时最后一个测试的样子:

return it("should filter a range of prices", function() {

它之前的样子(这些被规范运行者跳过):

it("should filter a specific price", function() {
4

1 回答 1

1

我尝试以不同的方式填充集合,现在它可以工作了。

跳过第一个测试时我的测试是什么样的(specrunner 说通过了 1 个规范,使用此代码跳过了 0 个):

describe "Products Collection", ->
    it "should filter a specific price", ->
        products = new Wishlist.Collections.Products
        products.add({name: 'product1', price: 15.99})
        products.add({name: 'product2', price: 21.99})
        products.add({name: 'product3', price: 21.99})
        products.add({name: 'product4', price: 1.99} )
        match = products.where({price: 21.99})
        expect(match.length).toBe(2)

    it "should filter a range of prices", ->
        products = new Wishlist.Collections.Products
        products.add({name: 'product1', price: 15.99})
        products.add({name: 'product2', price: 21.99})
        products.add({name: 'product3', price: 21.99})
        products.add({name: 'product4', price: 1.99})
        expect(products.priceFilter(16,25).size()).toBe(2)

他们现在的样子(正常工作):

describe "Products Collection", ->
    it "should filter a specific price", ->
        products = new Wishlist.Collections.Products [{name: 'product1', price: 15.99}, {name: 'product2', price: 21.99}, {name: 'product3', price: 21.99}, {name: 'product4', price: 1.99}]
        match = products.where({price: 21.99})
        expect(match.length).toBe(2)

    it "should filter a range of prices", ->
        products = new Wishlist.Collections.Products
        products.add({name: 'product1', price: 15.99})
        products.add({name: 'product2', price: 21.99})
        products.add({name: 'product3', price: 21.99})
        products.add({name: 'product4', price: 1.99})
        expect(products.priceFilter(16,25).size()).toBe(2)

As you can see, using products.add() couldn't be causing the issue, since it works in the 2nd test. I've no clue why it mattered..

于 2012-06-12T07:43:10.897 回答