本文整理汇总了TypeScript中angular2-meteor.ObservableCursor类的典型用法代码示例。如果您正苦于以下问题:TypeScript ObservableCursor类的具体用法?TypeScript ObservableCursor怎么用?TypeScript ObservableCursor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObservableCursor类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('toObservable', function() {
let collection : Mongo.Collection;
let cursor : Mongo.Cursor;
let observable : ObservableCursor;
beforeEach(function() {
collection = new Mongo.Collection(null);
collection.allow({
insert: function () {
return true;
},
update: function () {
return true;
},
remove: function () {
return true;
}
});
cursor = collection.find({});
observable = toObservable(cursor);
});
it ("Should wrap the Mongo.Cursor and return RxJS Observable", function() {
expect(observable instanceof Observable).to.equal(true);
});
it ("Should not use the actual Cursor 'observe' method without Observable subscription", function() {
let spy = sinon.spy(cursor, "observe");
expect(spy.called).to.equal(false);
spy.restore();
});
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 not trigger subscription callback when creating the subscription", function() {
let spy = sinon.spy();
let subscriptionHandler = observable.subscribe(spy);
expect(spy.called).to.equal(false);
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 trigger subscription callback when removing data to the collection", function() {
let spy = sinon.spy();
let subscriptionHandler = observable.subscribe(spy);
let idToRemove = collection.insert({test: true});
collection.remove(idToRemove);
expect(spy.callCount).to.equal(2);
subscriptionHandler.unsubscribe();
});
it ("Should trigger subscription callback when updating data on the collection", function() {
let spy = sinon.spy();
let subscriptionHandler = observable.subscribe(spy);
let idToUpdate = collection.insert({test: true});
collection.update({_id: idToUpdate}, {$set: {test: false}});
expect(spy.callCount).to.equal(2);
subscriptionHandler.unsubscribe();
});
it ("Should trigger the subscription callback multiple times when inserting multiple objects", function() {
let spy = sinon.spy();
let subscriptionHandler = observable.subscribe(spy);
collection.insert({test: 1});
collection.insert({test: 2});
collection.insert({test: 3});
expect(spy.callCount).to.equal(3);
subscriptionHandler.unsubscribe();
});
it ("Should NOT trigger the subscription callback when trying to update non-existing object", function() {
let spy = sinon.spy();
let subscriptionHandler = observable.subscribe(spy);
collection.insert({test: 1});
collection.update({test: 'B'}, {$set: {test: 'C'}});
expect(spy.callCount).to.equal(1);
subscriptionHandler.unsubscribe();
});
//.........这里部分代码省略.........
开发者ID:DAB0mB,项目名称:angular2-meteor,代码行数:101,代码来源:to-observable.spec.ts
示例2: it
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();
});
开发者ID:DAB0mB,项目名称:angular2-meteor,代码行数:7,代码来源:to-observable.spec.ts
注:本文中的angular2-meteor.ObservableCursor类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论