it('all collection changes are handled', function() { var differ = new MongoCursorDiffer(null /*cdRef*/, fakeFactory); differ.diff(fakeCursor); var changes = [ new AddChange(5, {name: 'some doc'}), new RemoveChange(15), new MoveChange(10, 20)]; fakeObserver.emit(changes); differ.diff(null); var forEachAddedItem = sinon.spy(function(addChange) { expect(addChange.item).to.equal(changes[0].item); expect(addChange.currentIndex).to.equal(changes[0].index); }); differ.forEachAddedItem(forEachAddedItem); expect(forEachAddedItem.calledOnce).to.equal(true); var forEachRemovedItem = sinon.spy(function(removeChange) { expect(removeChange.previousIndex).to.equal(changes[1].index); }); differ.forEachRemovedItem(forEachRemovedItem); expect(forEachRemovedItem.calledOnce).to.equal(true); var forEachMovedItem = sinon.spy(function(moveChange) { expect(moveChange.previousIndex).to.equal(changes[2].fromIndex); expect(moveChange.currentIndex).to.equal(changes[2].toIndex); }); differ.forEachMovedItem(forEachMovedItem); expect(forEachMovedItem.calledOnce).to.equal(true); });
beforeEach(function() { zoneSpy = sinon.spy(gZone, 'run'); unpatchMeteor(); autorunSpy = sinon.stub(Tracker, 'autorun'); subscribeSpy = sinon.stub(Meteor, 'subscribe'); callSpy = sinon.stub(Meteor, 'call'); patchMeteor(); });
it ("Should stop the observation of the Mongo.Collection when disposing the Observable", function() { let stopSpy = sinon.spy(); let spy = sinon.stub(cursor, "observe", function() { return { stop: stopSpy } }); let subscriptionHandler = observable.subscribe(function() {}); subscriptionHandler.unsubscribe(); expect(stopSpy.callCount).to.equal(1); spy.restore(); });
it('all collection changes are handled', function() { var differ = new MongoCursorDiffer(null /*cdRef*/, fakeFactory); differ.diff(fakeCursor); var changes = [ new AddChange(5, {name: 'some doc'}), new RemoveChange(15), new MoveChange(10, 20)]; fakeObserver.emit(changes); differ.diff(null); let count = 0; var forEachOperation = sinon.spy(function(record, previousIndex, index) { let change = changes[count]; expect(record.item).to.equal(change.item); if (count == 0) { expect(index).to.equal(change.index); } if (count == 1) { expect(previousIndex).to.equal(change.index); } if (count == 2) { expect(previousIndex).to.equal(change.fromIndex); expect(index).to.equal(change.toIndex); } count++; }); differ.forEachOperation(forEachOperation); expect(forEachOperation.callCount).to.equal(3); });
it('with autoBind', function() { var callback = sinon.spy(); var args = ['method', 'foo1', 'foo2', callback, true]; component.call.apply(component, args); expect(meteorCall.calledOnce).to.equal(true); expect(meteorCall.args[0]).to.deep.equal(_.initial(args)); });
it ("Should use the actual Cursor 'observe' after using Observable subscription", function() { let spy = sinon.spy(cursor, "observe"); let subscriptionHandler = observable.subscribe(() => {}); expect(spy.calledOnce).to.equal(true); spy.restore(); subscriptionHandler.unsubscribe(); });
it ("Should trigger subscription callback when adding data to the collection", function() { let spy = sinon.spy(); let subscriptionHandler = observable.subscribe(spy); collection.insert({test: true}); expect(spy.calledOnce).to.equal(true); subscriptionHandler.unsubscribe(); });
it ("Should isReactive return true when not calling nonReactive", function() { let spy = sinon.spy(); let observable2 = toObservable(cursor); let subscriptionHandler = observable2.subscribe(spy); expect(observable2.isReactive()).to.equal(true); subscriptionHandler.unsubscribe(); });
it('new cursor being handled properly', function() { var emptyFakeFactory = new fakes.ObserverFactoryFake(fakeObserver); var differ = new MongoCursorDiffer(null /*cdRef*/, emptyFakeFactory); differ.diff(fakeCursor); var changes1 = [ new AddChange(5, {name: 'cursor1 doc'})]; // This is ideally should be done via the cursor. differ.observer.emit(changes1); differ.diff(null); var fakeCursor1 = new fakes.MongoCollectionCursorFake(); differ.diff(fakeCursor1); var changes2 = [ new AddChange(10, {name: 'cursor2 doc'})]; differ.observer.emit(changes2); differ.diff(null); var forEachAddedItem = sinon.spy(function(addChange) { expect(addChange.item).to.equal(changes2[0].item); expect(addChange.currentIndex).to.equal(changes2[0].index); }); differ.forEachAddedItem(forEachAddedItem); expect(forEachAddedItem.calledOnce).to.equal(true); });
beforeEach(function() { ngZone = ngCore.createNgZone(); zoneSpy = sinon.spy(ngZone, 'run'); component = new MeteorComponent(ngZone); // global.Promise is only defined in the context, // but pure Promise itself, hence, failing tests. PromiseQ.wrapPush = cb => cb; });