oclif / fancy-test

extends mocha with helpful, chainable extensions
https://npmjs.com/package/fancy-test
61 stars 9 forks source link

Use context within stub #27

Open b4nst opened 5 years ago

b4nst commented 5 years ago

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')
})
APTy commented 1 year ago

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