-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add wrapper option to render/testHook #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I am thinking if we really need it as a // define
const testHookWithNameContext = (callback, wrapperProps) => {
let result
testHook(
() => {
result = callback()
},
props => <NameContext.Provider {...wrapperProps} {...props} />,
)
return result
}
// use
const [a, b] = testHookWithNameContext(myCustomHook, {value: "ABC"}) |
I think I still prefer the option object and here's why: Positional arguments can be confusing for uncommon options. Someone new to a codebase can figure out what {wrapper} means but would have to look in the docs for the meaning of the second argument and might think it's somehow required. For Edit: Also, you may need some of the other render options to test hooks in Karma or something. |
Ok, I agree with your reasoning. I will take a stab at this probably today as I need it in my codebase anyway. |
One thing might be rather confusing in case of more complex wrapper. What to do with passed const testHookWithContexts = (callback, { nameValue, otherValue }) => {
let result
testHook(
() => {
result = callback()
},
props => (
<NameContext.Provider value={nameValue}>
<OtherContext.Provider value={otherValue} {...props} />
</NameContext.Provider>
)
)
return result
} In this case, the I was thinking for a moment to utilize Alternative approach could be passing array of nodes and let the |
@alexkrolick Feel free to close, forgot to use a magic word in the PR :) |
@FredyC good point that figuring out where to put ...props is confusing. Better to destructure ({children}) in the docs I think. |
See #283 (comment)
The text was updated successfully, but these errors were encountered: