wrapper for testHook#296
Conversation
|
Maybe the examples can just destructure children instead of spreading all the props. Children is all that's needed right? |
It's a bit bulkier this way, but I guess there is no other more graceful way without introducing extra complexity. testHook(callback, {
wrapper: ({ children }) => (
<NameContext.Provider value={nameValue}>
<OtherContext.Provider value={otherValue}>
{children}
</OtherContext.Provider>
</NameContext.Provider>
)
})Btw, what about docs? I am not sure how to contribute there... Not even mentioning that |
|
@kentcdodds Are you ok with ignoring that eslint rule in tests (last commit)? If yes and documentation will be tackled later, then it's ready for merge. |
kentcdodds
left a comment
There was a problem hiding this comment.
This is fine. Docs will go on the docs website. Would love a contribution the too of you please. Thanks!
|
🎉 This PR is included in version 5.7.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
|
@kentcdodds Would not mind contributing, but I do have trouble finding the repo for docs. Would be a good idea to mention that in CONTRIBUTING. |
Agreed! Would you like to add a note about that? The docs repo is linked in the docs: https://github.com/alexkrolick/testing-library-docs |
|
I'd like to do a follow-up PR to add this option to Thanks @FredyC! |
|
Hi. Could you guys please let me know where is the docs to see how to implement The |
|
@ThanhPhat1080 Yea well, docs are kinda behind on this. I want to dive into that but got some other hurdles on the path. As for your example, you need this. testHook(
() => {
accountState = useTestContext();
},
{
wrapper: ({ children }) => (
<BrowserRouter>
<AccountProvider>
<AuthenticationForm>{children}</AuthenticationForm>
</AccountProvider>
</BrowserRouter>
),
},
);It's not intuitive much for sure and I am not too happy about it either. I am not sure if it could somehow automagically inject those children there. |
|
Thanks @FredyC It work for now, this is my code to let it work testHook(
() => {
accountState = useTestContext();
},
{
wrapper: ({ children }) => (
<BrowserRouter>
<AccountProvider>
{children}
<AuthenticationForm />
</AccountProvider>
</BrowserRouter>
),
},
);I have a question. Example my component have button and when fire click on it, it should change the context-value and update UI. I want to test that action and test the UI is updated or not. I tried using |
|
Docs PR for testHook: testing-library/testing-library-docs#32 |
|
@ThanhPhat1080 testHook is meant to test the return value of custom hooks. For testing components that use the hooks, you test them the normal way, with render. |
|
Thanks @alexkrolick |
|
🎉 This issue has been resolved in version 5.9.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
What:
Implementation of #293 based on discussion in #283.
Why:
To allow specifying a wrapper component tree around the testHook tree.
Checklist:
I am not too happy about spreading
propsthere. In simple cases of a one Provider it's fine, but in the example above it might be confusing what you are supposed to do there.