-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Need help with unit testing generated classes #157
Comments
HI @OlIvAl, I'll see what I can do but allow me to challange your testing approach. Because the main strengh of TSS (and Emotion) is to be able to generate the styles dynamically and get rid of const MenuItem: FC<IProps> = ({
label,
url,
iconSrc,
active = false,
}) => {
const { classes, cx } = useMenuItemStyles({ active });
return (
<a
href={url}
target="_blank"
rel="noreferrer"
data-testid="menu-item-link"
className={сlasses.link}
>
{label}
</a>
);
};
const useMenuItemStyles = makeStyles<{ active: boolean; }>()((theme, { active }) => ({
link: {
// generate the style dynamically using active
}
})); If I wand to provide a mock I have to be able to generate a fingerprint of the params and the theme state, wich isn't trivial to do safely. |
Afterthough: |
Well, I checked and Emotion does snapshot testing. This comes at a cost because you have to maintain your code AND the generated snapshots. I know there's convenience to regenerate the snapshots on almost any test engine, but I'd rather monkey patch the makeStyles method. Does someone know how this could be done or approached? Regardless of my preference for monkey patching, it would be great to have some examples on the docs for unit testing, or testing in general. Thanks in advance! |
Hello there!
I'm using your library in my project. Unfortunately, I couldn't find any examples of writing unit tests for classes generated by the useStyles hook (which returns makeStyles function). For example:
This test, or any other similar test, cannot pass because the active class does not exist. Instead, a class with a hash is generated. Is it possible to control or mock this generation process? In the past, MUI had a StylesProvider where you could set the class name generator using the generateClassName prop.
For example:
I couldn't find similar mechanisms in your library.
The text was updated successfully, but these errors were encountered: