You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
I have a Loading, Error, Data State in a component. Think of it as a Switch Statement. on Steroids. I want to test that Logic. So, I wrote the below code:
The below code works perfectly. Absolutely fine. But I have a problem with it. I need to call Logic Component in every single it statement. Which makes it hard to read, check and maintain.
In case it makes a difference, the renderWithRouter I am using is a custom one, I wrote, and you can see it below:
/* {renderWithRouter} Helper Component is meant to be used only for Testing.
* Use it if you want to wrap you Component with react-router
*
* @param MockHistory: History Object. Similar to MemoryRouter.
* @param MockWrapper: Wrapping the children with Router with {history}
*
* @return All the component, along with their Wrapper and history
*/
const renderWithRouter = (component: JSX.Element, route: string) => {
const MockHistory = createMemoryHistory({ initialEntries: [route] });
const MockWrapper = ({ children }: any) => <Router history={MockHistory}>{children}</Router>;
return { ...render(component, { wrapper: MockWrapper }), MockHistory };
};
Is there a way to re-use Component with their unique props, in every test? And in general is this pattern consider acceptable? What should we do in situation like that? My desired code would looked something like that:
Is the above possible? I haven't been able to make it work. Basically, state isn;t clean between it statements, and I resorted to the individual initialisation. Thank you!!
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have a
Loading
,Error
,Data
State in a component. Think of it as a Switch Statement. on Steroids. I want to test that Logic. So, I wrote the below code:The below code works perfectly. Absolutely fine. But I have a problem with it. I need to call
Logic
Component in every singleit
statement. Which makes it hard toread
,check
andmaintain
.Is there a way to re-use
Component
with their uniqueprops
, in every test? And in general is this pattern consider acceptable? What should we do in situation like that? My desired code would looked something like that:Is the above possible? I haven't been able to make it work. Basically, state isn;t clean between
it
statements, and I resorted to the individual initialisation. Thank you!!The text was updated successfully, but these errors were encountered: