當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript angular2-meteor.ObservableCursor類代碼示例

本文整理匯總了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;未經允許,請勿轉載。