我尝试以不同的方式填充集合,现在它可以工作了。
跳过第一个测试时我的测试是什么样的(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..