2

I have a meteor app and I try to write the following tests:

if (Meteor.isClient) {
    describe('System', () => {
        describe('check that the system is not active', () => {
            it('DB table is updated', () => {
                HTTP.post(server + "/system", {"data":{"active": "0"}}, function () {console.log("POST sent")});
                Tracker.autorun((computation) => {
                    if (!System.findOne({}) || (System.findOne({}) && System.findOne({}).active)) {console.log("waiting");return;}
                    computation.stop();
                });
                return assert.equal(System.findOne({}).active, false);
            });
            it('Can see it active in UI', () => {
                return assert.equal($('.status').text().trim(), "The system is not active");
            });
        });
        describe('check that the system is active', () => {
            it('DB table is updated', () => {
                HTTP.post(server + "/system", {"data":{"active": "1"}}, function () {console.log("POST sent")});
                Tracker.autorun((computation) => {
                    if (!(System.findOne({}) && System.findOne({}).active)) {return;}
                    computation.stop();
                });
                return assert.equal(System.findOne({}).active, true);
            });
            it('Can see it active in UI', () => {
                return assert.equal($('.status').text().trim(), "The system is active");
            });
        });
    });
}

My problem is that I get inside the Tracker of the first test only after the second test has finished and all my results are not worth it. I want to wait for the Tracker somehow before starting to run another test.

I tried afterFlushPromise, waitForSubscriptions, Tracker.flush() and even denodeify from meteor documentation, but nothing seem to help.

Is anyone have an idea?

coagmano
  • 5,542
  • 1
  • 28
  • 41
alexarsh
  • 5,123
  • 12
  • 42
  • 51

0 Answers0