|
1 | 1 | import * as React from 'react'; |
2 | 2 | import { expect } from 'chai'; |
3 | | -import { createMount, describeConformanceV5, createClientRender } from 'test/utils'; |
| 3 | +import { createMount, describeConformanceV5, createClientRender, screen } from 'test/utils'; |
4 | 4 | import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles'; |
5 | 5 | import Grid from './Grid'; |
6 | 6 | import classes from './gridClasses'; |
@@ -92,51 +92,56 @@ describe('<Grid />', () => { |
92 | 92 | it('should generate the right values', function test() { |
93 | 93 | if (/jsdom/.test(window.navigator.userAgent)) this.skip(); |
94 | 94 |
|
| 95 | + const parentWidth = 500; |
95 | 96 | const remValue = 16; |
96 | 97 | const remTheme = createMuiTheme({ |
97 | 98 | spacing: (factor) => `${0.25 * factor}rem`, |
98 | 99 | }); |
99 | 100 |
|
100 | | - const { container, getByTestId } = render( |
101 | | - <ThemeProvider theme={remTheme}> |
102 | | - <Grid container spacing={2}> |
103 | | - <Grid item data-testid="first-custom-theme" /> |
104 | | - <Grid item /> |
105 | | - </Grid> |
106 | | - </ThemeProvider>, |
| 101 | + const { rerender } = render( |
| 102 | + <div style={{ width: parentWidth }}> |
| 103 | + <ThemeProvider theme={remTheme}> |
| 104 | + <Grid data-testid="grid" container spacing={2}> |
| 105 | + <Grid item data-testid="first-custom-theme" /> |
| 106 | + <Grid item /> |
| 107 | + </Grid> |
| 108 | + </ThemeProvider> |
| 109 | + </div>, |
107 | 110 | ); |
108 | 111 |
|
109 | | - expect(container.firstChild).toHaveComputedStyle({ |
| 112 | + expect(screen.getByTestId('grid')).toHaveComputedStyle({ |
110 | 113 | marginTop: `${-1 * remValue * 0.25}px`, // '-0.25rem' |
111 | 114 | marginBottom: `${-1 * remValue * 0.25}px`, // '-0.25rem' |
112 | 115 | marginLeft: `${-1 * remValue * 0.25}px`, // '-0.25rem' |
113 | 116 | marginRight: `${-1 * remValue * 0.25}px`, // '-0.25rem' |
114 | | - // width: `${750 + remValue * 0.5}px`, // 'calc(100% + 0.5rem)' |
| 117 | + width: `${parentWidth + remValue * 0.5}px`, // 'calc(100% + 0.5rem)' |
115 | 118 | }); |
116 | 119 |
|
117 | | - expect(getByTestId('first-custom-theme')).toHaveComputedStyle({ |
| 120 | + expect(screen.getByTestId('first-custom-theme')).toHaveComputedStyle({ |
118 | 121 | paddingTop: `${0.25 * remValue}px`, // 0.25rem |
119 | 122 | paddingBottom: `${0.25 * remValue}px`, // 0.25rem |
120 | 123 | paddingLeft: `${0.25 * remValue}px`, // 0.25rem |
121 | 124 | paddingRight: `${0.25 * remValue}px`, // 0.25rem |
122 | 125 | }); |
123 | 126 |
|
124 | | - const { container: defaultThemeContainer, getByTestId: defaultThemeGetByTestId } = render( |
125 | | - <Grid container spacing={2}> |
126 | | - <Grid item data-testid="first-default-theme" /> |
127 | | - <Grid item /> |
128 | | - </Grid>, |
| 127 | + rerender( |
| 128 | + <div style={{ width: parentWidth }}> |
| 129 | + <Grid data-testid="grid" container spacing={2}> |
| 130 | + <Grid item data-testid="first-default-theme" /> |
| 131 | + <Grid item /> |
| 132 | + </Grid> |
| 133 | + </div>, |
129 | 134 | ); |
130 | 135 |
|
131 | | - expect(defaultThemeContainer.firstChild).toHaveComputedStyle({ |
| 136 | + expect(screen.getByTestId('grid')).toHaveComputedStyle({ |
132 | 137 | marginTop: '-8px', |
133 | 138 | marginBottom: '-8px', |
134 | 139 | marginLeft: '-8px', |
135 | 140 | marginRight: '-8px', |
136 | | - // width: `${750 + 16}px`, // 'calc(100% + 16px)' |
| 141 | + width: `${parentWidth + 16}px`, // 'calc(100% + 16px)' |
137 | 142 | }); |
138 | 143 |
|
139 | | - expect(defaultThemeGetByTestId('first-default-theme')).toHaveComputedStyle({ |
| 144 | + expect(screen.getByTestId('first-default-theme')).toHaveComputedStyle({ |
140 | 145 | paddingTop: '8px', |
141 | 146 | paddingBottom: '8px', |
142 | 147 | paddingLeft: '8px', |
|
0 commit comments