Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit 148e9e2

Browse files
committed
tests: fix test with styled-components v4
1 parent b25675a commit 148e9e2

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

packages/shared/core/utils/breakpoints.test.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
2-
import { shallow } from 'enzyme'
3-
import styled, { ThemeProvider } from 'styled-components'
2+
import { mount } from 'enzyme'
3+
import styled from 'styled-components'
44
import {
55
DEFAULT_BREAKPOINTS,
66
getBreakpoints,
@@ -16,7 +16,6 @@ import {
1616

1717
describe('breakpoints utils', () => {
1818
let props
19-
let shallowWithTheme
2019

2120
beforeEach(() => {
2221
props = {
@@ -29,13 +28,6 @@ describe('breakpoints utils', () => {
2928
},
3029
},
3130
}
32-
33-
shallowWithTheme = (tree, theme = props.theme) => {
34-
const context = shallow(<ThemeProvider theme={theme} />)
35-
.instance()
36-
.getChildContext()
37-
return shallow(tree, { context })
38-
}
3931
})
4032

4133
describe('#getBreakpoints', () => {
@@ -110,7 +102,7 @@ describe('breakpoints utils', () => {
110102
${up('lg', { color: 'yellow' })};
111103
`
112104

113-
const wrapper = shallowWithTheme(<Dummy />)
105+
const wrapper = mount(<Dummy {...props} />)
114106
expect(wrapper).toHaveStyleRule('color', 'blue')
115107
expect(wrapper).toHaveStyleRule('color', 'red', {
116108
media: '(min-width:10px)',
@@ -126,7 +118,7 @@ describe('breakpoints utils', () => {
126118
${up('xs', 'color: red')};
127119
`
128120

129-
const wrapper = shallowWithTheme(<Dummy />)
121+
const wrapper = mount(<Dummy {...props} />)
130122
expect(wrapper).toHaveStyleRule('color', 'red')
131123
})
132124
})
@@ -139,7 +131,7 @@ describe('breakpoints utils', () => {
139131
${down('sm', { color: 'yellow' })};
140132
`
141133

142-
const wrapper = shallowWithTheme(<Dummy />)
134+
const wrapper = mount(<Dummy {...props} />)
143135
expect(wrapper).toHaveStyleRule('color', 'blue')
144136
expect(wrapper).toHaveStyleRule('color', 'red', {
145137
media: '(max-width:9.98px)',
@@ -155,7 +147,7 @@ describe('breakpoints utils', () => {
155147
${down('lg', 'color: red')};
156148
`
157149

158-
const wrapper = shallowWithTheme(<Dummy />)
150+
const wrapper = mount(<Dummy {...props} />)
159151
expect(wrapper).toHaveStyleRule('color', 'red')
160152
})
161153
})
@@ -168,7 +160,7 @@ describe('breakpoints utils', () => {
168160
${between('xs', 'sm', { background: 'yellow' })};
169161
`
170162

171-
const wrapper = shallowWithTheme(<Dummy />)
163+
const wrapper = mount(<Dummy {...props} />)
172164
expect(wrapper).toHaveStyleRule('color', 'blue')
173165
expect(wrapper).toHaveStyleRule('color', 'red', {
174166
media: '(max-width:4.98px)',
@@ -184,7 +176,7 @@ describe('breakpoints utils', () => {
184176
${between('md', 'lg', 'color: red')};
185177
`
186178

187-
const wrapper = shallowWithTheme(<Dummy />)
179+
const wrapper = mount(<Dummy {...props} />)
188180
expect(wrapper).toHaveStyleRule('color', 'blue')
189181
expect(wrapper).toHaveStyleRule('color', 'red', {
190182
media: '(min-width:10px)',
@@ -197,7 +189,7 @@ describe('breakpoints utils', () => {
197189
${between('sm', 'md', 'color: red')};
198190
`
199191

200-
const wrapper = shallowWithTheme(<Dummy />)
192+
const wrapper = mount(<Dummy {...props} />)
201193
expect(wrapper).toHaveStyleRule('color', 'blue')
202194
expect(wrapper).toHaveStyleRule('color', 'red', {
203195
media: '(min-width:5px) and (max-width:9.98px)',

packages/shared/core/utils/styles.test.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import React from 'react'
2-
import { shallow } from 'enzyme'
3-
import styled, { ThemeProvider } from 'styled-components'
2+
import { mount } from 'enzyme'
3+
import styled from 'styled-components'
44
import * as styles from './styles'
55

6-
const shallowWithTheme = (tree, theme = {}) => {
7-
const context = shallow(<ThemeProvider theme={theme} />)
8-
.instance()
9-
.getChildContext()
10-
return shallow(tree, { context })
11-
}
12-
136
describe('styles', () => {
147
describe.each([
158
[
@@ -421,15 +414,15 @@ describe('styles', () => {
421414
it('should support basic value', () => {
422415
config.expectations.forEach(([value, expected]) => {
423416
const props = { [name]: value }
424-
const wrapper = shallowWithTheme(<Dummy {...props} />, config.theme)
417+
const wrapper = mount(<Dummy theme={config.theme} {...props} />)
425418
expect(wrapper).toHaveStyleRule(config.styleRule, String(expected))
426419
})
427420
})
428421

429422
it('should support breakpoints value', () => {
430423
config.expectations.forEach(([value, expected]) => {
431424
const props = { [name]: { md: value } }
432-
const wrapper = shallowWithTheme(<Dummy {...props} />, config.theme)
425+
const wrapper = mount(<Dummy theme={config.theme} {...props} />)
433426
expect(wrapper).toHaveStyleRule(config.styleRule, String(expected), {
434427
media: '(min-width:768px)',
435428
})

0 commit comments

Comments
 (0)