0

I've got a problem whereas sometimes my tests fail due to the asserts being run before the response comes back here in my integration tests:

   it('should find all countries when no id is specified', co.wrap(function *(){
        var uri = '/countries';
        var response = yield request.get(uri);

        should.exist(response.body);
        response.status.should.equal(200);
    }));

Not sure how to tweak mocha or supertest to wait or if I should use a promise here or what. I'm using generators with mocha here.

Adding a longer timeout to mocha does absolutely nothing. The query behind this particular test takes a bit longer than my other tests. My other tests run just fine.

PositiveGuy
  • 17,621
  • 26
  • 79
  • 138
  • A quick look shows that `co.wrap` uses promises everywhere. Are you sure the `response` is actually a response and not a promise? You might try using `co(...)` instead of `co.wrap(...)` to get a plain object from `yield`. – Wojciech Ptak Oct 19 '15 at 07:16
  • What is the exact error message you get when your test fails? Supertest has its *own* timeout which is different from Mocha's timeout. The two are *independent*. You could set Mocha's timeout to 3 hours and supertest would still timeout. (By the way `co.wrap` is correct.) – Louis Oct 19 '15 at 11:44
  • It goes immediately to yellow – PositiveGuy Oct 19 '15 at 13:15
  • 1
    Co will not work. Already tried that a long time ago.. Someone mentioned to use co-wrap and ever since I was able to finally run my mocha test via generators – PositiveGuy Oct 19 '15 at 13:17

0 Answers0