Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing spec for sorted block with missing sorted property #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions spec/observe-sorted-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]]);
});

});