Skip to content Skip to sidebar Skip to footer

How Do I Test Nested ES6 Generators Using Mocha?

I'm trying to use co-mocha to test some nested generators functionality in my koa app. The class works just fine at runtime, but when I attempt to test the functionality, I cannot

Solution 1:

Without mocha-generators, the it callback returns a generator that will not be run by anyone. You'd need to wrap it in co manually so that mocha would receive a promise.

With mocha-generators, your generator is executed but yields a generator function. That's not expected, you are supposed to yield promises. You need to call the generator function that the create() call returns yourself, and then you shouldn't yield a generator itself but rather delegate to it via yield*:

let result = yield* fooService.create()();

Post a Comment for "How Do I Test Nested ES6 Generators Using Mocha?"