我有一个流星应用程序,我尝试编写以下测试:
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");
});
});
});
}
我的问题是我只有在第二次测试完成后才进入第一次测试的跟踪器,我所有的结果都不值得。在开始运行另一个测试之前,我想以某种方式等待 Tracker。
我尝试了 afterFlushPromise、waitForSubscriptions、Tracker.flush() 甚至从流星文档中去节点化,但似乎没有任何帮助。
有人有想法吗?