-
Notifications
You must be signed in to change notification settings - Fork 97
feat(testing): add renderWithTheme #171
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| Signature: | ||
|
|
||
| - `renderWithTheme(reactNode, { rtl: boolean, theme: object, enzymeOptions: object })` | ||
|
|
||
| ```jsx static | ||
| import { Tabs, TabPanel } from '@zendeskgarden/react-tabs'; | ||
| import { renderWithTheme } from '@zendeskgarden/react-testing'; | ||
|
|
||
| const TabsExample = ( | ||
| <Tabs> | ||
| <TabPanel label="Tab 1" key="tab-1"> | ||
| Tab 1 content | ||
| </TabPanel> | ||
| <TabPanel label="Tab 2" key="tab-2"> | ||
| Tab 2 content | ||
| </TabPanel> | ||
| </Tabs> | ||
| ); | ||
|
|
||
| const RtlTabs = renderWithTheme(TabsExample, { rtl: true }); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * Copyright Zendesk, Inc. | ||
| * | ||
| * Use of this source code is governed under the Apache License, Version 2.0 | ||
| * found at http://www.apache.org/licenses/LICENSE-2.0. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { mount, render } from 'enzyme'; | ||
| import { ThemeProvider as StyledThemeProvider } from 'styled-components'; | ||
| import { ThemeProvider } from '@zendeskgarden/react-theming'; | ||
|
|
||
| /** | ||
| * Render a component with provided RTL and Theme | ||
| * @param {EnzymeWrapper} tree | ||
| * @param {Object} ThemeProperties { rtl: boolean, theme: object, enzymeOptions: object } | ||
| */ | ||
| const renderWithTheme = (tree, { rtl, theme, enzymeOptions } = {}) => { | ||
| const context = mount(<ThemeProvider theme={theme} rtl={rtl} />) | ||
| .childAt(0) | ||
| .instance() | ||
| .getChildContext(); | ||
|
|
||
| return render( | ||
| tree, | ||
| { context, childContextTypes: StyledThemeProvider.childContextTypes }, | ||
| enzymeOptions | ||
| ); | ||
| }; | ||
|
|
||
| export default renderWithTheme; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this any different to the above
mountWithTheme?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little lost as well. The only difference I can see is that
mountWithThemeis passing the childContext types through the context with{ context, childContextTypes: StyledThemeProvider.childContextTypes },Without that you are probably seeing some Styled-Components
console.warns in the console?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryanseddon the only difference from the
mountWithThemeis that it callsrenderinstead ofmountfor the passed component. And this is the main purpose of this helper.@Austin94 good catch! Added
childContextTypesto the options.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What use-case would this have for testing? The
react-testingpackages are mostly around utilities for enzyme & jest testing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly for snapshots testing with enzyme. Useful when a component composites smaller none exportable components and mounting to DOM is not needed.
shallowdoesn't render subcomponents andrenderis doing this down to html elements.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification @ssidorchik. Is this change intended to clean up some of our tests or are you depending on this in your own codebase for testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already using the enzyme's
renderon a separate project. And would like to add the theme support.