Skip to content

Commit 142c0a8

Browse files
authored
Merge pull request #22 from eps1lon/feat/grid-migrate-to-emotion-test-width
screen size agnostic grid tests
2 parents 40d664d + 6e03c35 commit 142c0a8

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

packages/material-ui/src/Grid/Grid.test.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { expect } from 'chai';
3-
import { createMount, describeConformanceV5, createClientRender } from 'test/utils';
3+
import { createMount, describeConformanceV5, createClientRender, screen } from 'test/utils';
44
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
55
import Grid from './Grid';
66
import classes from './gridClasses';
@@ -92,51 +92,56 @@ describe('<Grid />', () => {
9292
it('should generate the right values', function test() {
9393
if (/jsdom/.test(window.navigator.userAgent)) this.skip();
9494

95+
const parentWidth = 500;
9596
const remValue = 16;
9697
const remTheme = createMuiTheme({
9798
spacing: (factor) => `${0.25 * factor}rem`,
9899
});
99100

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>,
107110
);
108111

109-
expect(container.firstChild).toHaveComputedStyle({
112+
expect(screen.getByTestId('grid')).toHaveComputedStyle({
110113
marginTop: `${-1 * remValue * 0.25}px`, // '-0.25rem'
111114
marginBottom: `${-1 * remValue * 0.25}px`, // '-0.25rem'
112115
marginLeft: `${-1 * remValue * 0.25}px`, // '-0.25rem'
113116
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)'
115118
});
116119

117-
expect(getByTestId('first-custom-theme')).toHaveComputedStyle({
120+
expect(screen.getByTestId('first-custom-theme')).toHaveComputedStyle({
118121
paddingTop: `${0.25 * remValue}px`, // 0.25rem
119122
paddingBottom: `${0.25 * remValue}px`, // 0.25rem
120123
paddingLeft: `${0.25 * remValue}px`, // 0.25rem
121124
paddingRight: `${0.25 * remValue}px`, // 0.25rem
122125
});
123126

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>,
129134
);
130135

131-
expect(defaultThemeContainer.firstChild).toHaveComputedStyle({
136+
expect(screen.getByTestId('grid')).toHaveComputedStyle({
132137
marginTop: '-8px',
133138
marginBottom: '-8px',
134139
marginLeft: '-8px',
135140
marginRight: '-8px',
136-
// width: `${750 + 16}px`, // 'calc(100% + 16px)'
141+
width: `${parentWidth + 16}px`, // 'calc(100% + 16px)'
137142
});
138143

139-
expect(defaultThemeGetByTestId('first-default-theme')).toHaveComputedStyle({
144+
expect(screen.getByTestId('first-default-theme')).toHaveComputedStyle({
140145
paddingTop: '8px',
141146
paddingBottom: '8px',
142147
paddingLeft: '8px',

0 commit comments

Comments
 (0)