rosshinkley / nightmare-examples

Examples and supplementary documentation for Nightmare
251 stars 46 forks source link

Is there a way to combine `.use` functionality with mocha-generators? #41

Open leimonio opened 7 years ago

leimonio commented 7 years ago

I would like to extract assertion functionality to separate helper functions. I'm already using mocha-generators and I'd like to implement the following case:

Assume we have a shared function like below:

function sharedFn(params) {
    return function* (nightmare) {
        yield nightmare.wait(1000) (...some functionality here)
    }
}

The snippet below works:

...
it('should combine use with a generator', function* () {
    yield nightmare.wait(1000)
    yield* sharedFn(params)(nightmare)
})
...

But how can I implement it with .use, like:

...
it('should combine use with a generator', function* () {
    yield nightmare
    .wait(1000)
    .use(sharedFn(params))
})
...