Skip to content

Commit

Permalink
chore(tests): Added unit tests for movedTo
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Oct 26, 2016
1 parent 4beae33 commit a254b96
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/client/unit/observable-cursor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,37 @@ describe('ObservableCursor', function () {
expect(spy.calledOnce).to.be.true;
});

it('Should trigger subscription callback when moving items in the collection', (done) => {
cursor = collection.find({}, {sort: {name: 1}});
observable = ObservableCursor.create(cursor);

let newDoc = {name: 'ZZZZ'};
let subHandler;
let count = 0;

let callback = docs => {
count++;

// 4 because: insert, insert, update, *move*
if (count === 4) {
let firstItem = docs[0];
expect(firstItem.name).to.equal("AAAA");
subHandler.unsubscribe();
done();
}
};

subHandler = observable.subscribe(callback);

let objectId = collection.insert(newDoc);

collection.insert({
name: "BBBB"
});

collection.update({_id: objectId}, { $set: {name: "AAAA"} });
});

it('Should trigger callback twice when inserting a doc and then removing it', () => {
let count = 0;
let subHandler;
Expand Down

0 comments on commit a254b96

Please sign in to comment.