• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript angular2-meteor.ObservableCursor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap