Jasmine 跳过了我所有的“it”测试,除了 describe block 中的最后一个测试 - 我在测试中使用了 coffeescript,我相信这可能是原因。当我查看由我的 .coffee 测试创建的已编译 JS 时,我发现只有最后一个“it”测试前面有“return”这个词,这可能是其余测试被跳过的原因。
我的问题是,如何让它“返回”所有测试?
最后一个测试编译后的样子:
return it("should filter a range of prices", function() {
它之前的那些看起来像什么(这些被 specrunner 跳过):
it("should filter a specific price", function() {
最佳答案
我尝试以不同的方式填充集合,现在可以了。
当第一个被跳过时我的测试看起来像什么(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)
如您所见,使用 products.add() 不会导致问题,因为它在第二次测试中有效。我不知道为什么这很重要..
关于javascript - Jasmine + coffeescript - Jasmine 跳过测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10985318/