describe-component icon indicating copy to clipboard operation
describe-component copied to clipboard

Add context helpers

Open suchipi opened this issue 7 years ago • 1 comments

describeComponent should expose setContext and context helpers that work the same as setProps and props, but for context.

suchipi avatar Dec 04 '17 20:12 suchipi

As of 1.1.0, you can pass options for enzyme's mount, shallow, or render functions into mountWrapper, shallowWrapper, or renderWrapper. This lets you set context like this:

describeComponent(MyComponent, ({ mountWrapper }) => {
  mountWrapper({ context: { some: "context", goes: "here" } });
});

However, the usage can be a bit awkward, because the context set in the first invocation of mountWrapper or shallowWrapper carries over to the next time mountWrapper or shallowWrapper is called (since the result is memoized). For this reason, I'd still like to eventually add setContext and context- but using enzyme's options is an easy workaround in the meantime.

suchipi avatar Jan 21 '18 05:01 suchipi