我試圖填充集合不同的方式,現在它工作。
什麼我的測試樣子時,第一次是被跳過(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()不會導致問題,因爲它在第二個測試中有效。我不知道爲什麼它很重要..
specrunner告訴我1規範通過時,實際上有2個規格。我修好了,但我不知道它爲什麼修復它。閱讀下面 –