Skip to content

Instantly share code, notes, and snippets.

@mixonic
Created December 11, 2013 15:51
Show Gist options
  • Save mixonic/7912835 to your computer and use it in GitHub Desktop.
Save mixonic/7912835 to your computer and use it in GitHub Desktop.
test("it slices the array", function() {
expect(7);
deepEqual(get(obj, 'sliced'), [1, 2]);
Ember.run(function() {
// [0, 1, 2, 3, 4, 5]
obj.get('array').insertAt(0, 0);
});
deepEqual(get(obj, 'sliced'), [0, 1]);
Ember.run(function() {
// [0]
obj.get('array').removeAt(1, 5);
});
deepEqual(get(obj, 'sliced'), [0]);
Ember.run(function() {
function assertChange(){
ok(true, "Calls observer on change.");
}
obj.addObserver('sliced.[]', assertChange);
// [0, 1]
obj.get('array').insertAt(1, 1);
obj.removeObserver('sliced.[]', assertChange);
});
deepEqual(get(obj, 'sliced'), [0, 1]);
Ember.run(function() {
function assertNoChange(){
ok(false, "Does not call observer for changes outside the slice.");
}
obj.addObserver('sliced.[]', assertNoChange);
// [0, 1, 2]
obj.get('array').pushObject(2);
obj.removeObserver('sliced.[]', assertNoChange);
});
deepEqual(get(obj, 'sliced'), [0, 1]);
Ember.run(function() {
// []
obj.get('array').removeAt(0, 3);
});
deepEqual(get(obj, 'sliced'), []);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment