Testing with custom theme palette
See original GitHub issueProblem description
If I create a custom theme and test a component that is leveraging a custom object from that theme, tests fail because that custom field is undefined, is there a documented way to test components with custom themes?
Steps to reproduce
Create a custom theme:
customTheme = {
"direction": "ltr",
"palette": {
"customObject": {
"customField1": "#FF0000"
},
......
}
Shallow render custom component with a custom theme.
shallow(
<MuiThemeProvider theme={customTheme} >
<ComponentThatUsesCustomField1 />
</MuiThemeProvider
).dive()
Will throw an undefined error at customObject.
Versions
- Material-UI: alpha v7
- React: 15.6.1
- Browser: latest
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Testing with custom theme palette · Issue #8000 · mui/material-ui
Problem description If I create a custom theme and test a component that is leveraging a custom object from that theme, tests fail...
Read more >Material-UI custom theme palette property yielding 'undefined ...
I encountered this today, the solution that fixed for me is this const useStyles = makeStyles((theme) => { return { ctaCopy: { color:...
Read more >Accelerating GitHub theme creation with color tooling
... a dedicated color tool and how they use it to create new color palettes for GitHub. ... Defining tones; Choosing colors; Testing...
Read more >Create a Customized Color Theme in Material-UI - Medium
In this article, I want to explain how to get started with Material-UI and customize a color palette theme to use for your...
Read more >Designing a Material Theme: Color
Crafting the perfect palette with Material Design and Figma. ... as well as slots for a custom background color, surface color (for elevated ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello,
I’m experiencing a similar issue. I’ve wrapped a
TextField
in aMuiThemeProvider
, so when usingjest
tests fail:createMuiTheme -> createPalette -> augmentColor ()
It seems that it’s unable to get the palette in the tests, even though it’s working perfectly in the rest of scenarios (no browser console logs complaining when
NODE_ENV='development'
, so our palette is well defined).Is there any workaround to include this context for our tests (with
shallow
)? Maybe theaugmentColor
should not be raising an error ifNODE_ENV='test'
?Thank you very much for your help.
I worked around this by manually adding the custom theme in to the context like so:
You can use the above logic to wrap
createShallow
or make it cleaner in any number of ways.