Skip to content

Commit bed10b1

Browse files
committed
Add additional StyleSheet tests for styled-components
1 parent d305c2a commit bed10b1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/__tests__/visitor.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const {
3131
ReactCurrentDispatcher
3232
} = (React: any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
3333

34+
const {
35+
StyleSheet
36+
} = require('styled-components').__DO_NOT_USE_OR_YOU_WILL_BE_HAUNTED_BY_SPOOKY_GHOSTS
37+
3438
let prevDispatcher = null
3539

3640
beforeEach(() => {
@@ -48,6 +52,10 @@ afterEach(() => {
4852
const Noop = () => null
4953

5054
describe('visitElement', () => {
55+
beforeEach(() => {
56+
StyleSheet.reset(true)
57+
})
58+
5159
it('walks Fragments', () => {
5260
const element = (
5361
<Fragment>
@@ -115,14 +123,32 @@ describe('visitElement', () => {
115123
[],
116124
() => {}
117125
)
126+
118127
expect(children.length).toBe(1)
119128
expect(children[0].type).toBe(Noop)
129+
expect(StyleSheet.master.tags.length).toBe(1)
130+
131+
const tag = StyleSheet.master.tags[0]
132+
expect(tag.css().trim()).toBe('')
133+
134+
expect(Object.keys(StyleSheet.master.deferred)).toEqual([
135+
expect.any(String)
136+
])
120137
})
121138

122139
it('walks StyledComponent wrapper elements', () => {
123140
const Comp = styled(Noop)``
124141
const children = visitElement(<Comp />, [], () => {})
142+
125143
expect(children.length).toBe(1)
144+
expect(StyleSheet.master.tags.length).toBe(1)
145+
146+
const tag = StyleSheet.master.tags[0]
147+
expect(tag.css().trim()).toBe('')
148+
149+
expect(Object.keys(StyleSheet.master.deferred)).toEqual([
150+
expect.any(String)
151+
])
126152
})
127153

128154
it('walks Providers and Consumers', () => {

0 commit comments

Comments
 (0)