fancy-test icon indicating copy to clipboard operation
fancy-test copied to clipboard

Use context within stub

Open b4nst opened this issue 6 years ago • 1 comments

Hi there,

Is it possible to use the context inside a stub ? It could be useful for use cases like this

import * as tmp from 'tmp-promise'
import {fancy} from 'fancy-test'
import {expect} from 'chai'

describe('suite', () => {
  fancy
    .add('tmpDir', () => tmp.dir())
    .stub(process, 'cwd', () => ctx.tmpDir.path) //Use the context here
    .do(ctx => expect(process.cwd()).to.equal(ctx.tmpDir.path))
    .finally(ctx => ctx.tmpDir.cleanup())
    .it('use context in stub')
})

b4nst avatar May 28 '19 14:05 b4nst

Is there any workaround to achieve something like this? Trying to use objects added to ctx to have more control over stubs, and would prefer not to use global state

APTy avatar Mar 16 '23 15:03 APTy