diff --git a/spec/observe-sorted-spec.js b/spec/observe-sorted-spec.js index b07dda8..7814c24 100644 --- a/spec/observe-sorted-spec.js +++ b/spec/observe-sorted-spec.js @@ -26,5 +26,49 @@ describe("sorted block observer", function () { expect(object.sorted).toEqual([array[2], array[0], array[1]]); }); + it("sorts objects missing the sorted property", function () { + + var array = [ + {key: 0}, + {key: 1}, + {key: 2} + ]; + + var object = Bindings.defineBindings({ + array: array + }, { + sorted: {"<-": "array.sorted{value}"} + }); + + expect(object.sorted.length).toEqual(3); + + array[2].value = 'a'; + array[1].value = 'b'; + array[0].value = 'c'; + + expect(object.sorted.length).toEqual(3); + expect(object.sorted).toEqual([array[2], array[1], array[0]]); + }); + + it("sorts objects with equal values", function () { + + var array = [ + {key: 0, value: "b"}, + {key: 1, value: "b"}, + {key: 2, value: "b"} + ]; + + var object = Bindings.defineBindings({ + array: array + }, { + sorted: {"<-": "array.sorted{value}"} + }); + + array[2].value = 'a'; + array[0].value = 'c'; + + expect(object.sorted).toEqual([array[2], array[1], array[0]]); + }); + });