我正在为Meteor JS应用程序编写服务器端单元测试。我使用推荐的Mocha框架和chai断言库。使用done()回调链接异步调用时遇到了一些麻烦,所以我决定使用meteor / promise。我正在使用和johanbrook:publication-collector来收集已发布的集合。
当我在promise中解析(集合)时,在随后的then()中,我能够在console.log中收集收集的集合,但断言语句将不起作用。每次运行时,mocha测试都会通过,即使断言应该不通过测试。
it('sample test', function() {
this.timeout(5000);
const collector = new PublicationCollector({ userId: Random.id() });
const some_collection = Factory.create('some_collection');
chai.assert.equal(some_collection.details.value, 100);
return new Promise(function(resolve) {
Contracts.getActiveContracts(); // updates some_collection.details.value
collector.collect('some_collection', function(collections) {
resolve(collections);
});
}).then(function(coll) {
console.log('collected lots:',coll.some_collection.details);
chai.assert.equal(null, coll.some_collection); //this is effectively invisible, why?
});
});
>>I201609-10:12:46.867(-5)? collected: { some_collection:
I200609-10:12:46.867(-5)? [ { _id: 'Qh4qQTwKTdHYtpA',
I200609-10:12:46.868(-5)? owner: 'kkishore',
I201609-10:12:46.868(-5)? createdAt: Tue Jun 06 2017 10:37:07 GMT-0500 (CDT),
I20160609-10:12:46.868(-5)? details: [Object] } ] }
我有什么遗失的吗?