Skip to content

More server-side reactivity tests #8

@Slava

Description

@Slava

Need more tests on observing a cursor. See examples in tests.js:

  it('can start observing', function (done) {
    coll.insert({ obj: 1 }).run();

    h = coll.orderBy({index:'id'}).limit(100).observe({
      added: function (doc) {
        if (doneObserving) assert.fail('should not get notified after a stopped observe');
        messages.push(['a', doc]);
      },
      changed: function (newDoc, oldDoc) {
        if (doneObserving) assert.fail('should not get notified after a stopped observe');
        messages.push(['c', newDoc, oldDoc]);
      },
      removed: function (doc) {
        if (doneObserving) assert.fail('should not get notified after a stopped observe');
        messages.push(['r', doc]);
      }
    });

    done();
  });

  it('gets initial data set', function (done) {
    expect(messages).to.have.length(1);
    var m = messages.shift();
    expect(m[0]).to.be.equal('a');
    expect(m[1].obj).to.be.equal(1);
    done();
  });

  it('notices inserts', function (done) {
    finishObserve(function () {
      coll.insert({ obj: 2 }).run();
    });
    expect(messages).to.have.length(1);
    var m = messages.shift();
    expect(m[0]).to.be.equal('a');
    expect(m[1].obj).to.be.equal(2);
    done();
  });

  it('notices updates', function (done) {
    finishObserve(function () {
      coll.filter(r.row('obj').gt(1)).update({obj: r.row('obj').add(3)}).run();
    });
    expect(messages).to.have.length(1);
    var m = messages.shift();
    expect(m[0]).to.be.equal('c');
    expect(m[1].obj).to.be.equal(5);
    expect(m[2].obj).to.be.equal(2);
    done();
  });

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions