Using Promises to test Meteor - Mocha

╄→гoц情女王★ 提交于 2019-12-12 03:37:44

问题


I'm writing server side unit tests for a Meteor JS application. I'm using the recommended Mocha framework, with chai assertion library. I had some trouble with chaining async calls with done() callback, so I decided to use meteor/promise. I'm using and johanbrook:publication-collector to collect the published collections.

When I resolve(collections) in the promise, In the subsequent then() I'm able to console.log the gathered collection, but the assert statement wouldn't work. The mocha test simply passes every time I run, even if the assertion should fail the test.

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] } ] }

Is there something I'm missing?

来源:https://stackoverflow.com/questions/37730569/using-promises-to-test-meteor-mocha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!