Skip to content

Commit 34bbff3

Browse files
committed
Reformat
1 parent 92ac0df commit 34bbff3

File tree

7 files changed

+142
-82
lines changed

7 files changed

+142
-82
lines changed

src/__tests__/element.js

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,45 @@ describe('typeOf', () => {
2020
it('correctly identifies all elements', () => {
2121
expect(typeOf({})).toBe(undefined)
2222

23-
expect(typeOf({
24-
$$typeof: is.Portal
25-
})).toBe(REACT_PORTAL_TYPE)
26-
27-
expect(typeOf({
28-
$$typeof: is.Element,
29-
type: is.ConcurrentMode
30-
})).toBe(REACT_CONCURRENT_MODE_TYPE)
31-
32-
expect(typeOf({
33-
$$typeof: is.Element,
34-
type: is.Fragment
35-
})).toBe(REACT_FRAGMENT_TYPE)
36-
37-
expect(typeOf({
38-
$$typeof: is.Element,
39-
type: is.Profiler
40-
})).toBe(REACT_PROFILER_TYPE)
41-
42-
expect(typeOf({
43-
$$typeof: is.Element,
44-
type: is.StrictMode
45-
})).toBe(REACT_STRICT_MODE_TYPE)
46-
47-
expect(typeOf({
48-
$$typeof: is.Element,
49-
type: is.Suspense
50-
})).toBe(REACT_SUSPENSE_TYPE)
23+
expect(
24+
typeOf({
25+
$$typeof: is.Portal
26+
})
27+
).toBe(REACT_PORTAL_TYPE)
28+
29+
expect(
30+
typeOf({
31+
$$typeof: is.Element,
32+
type: is.ConcurrentMode
33+
})
34+
).toBe(REACT_CONCURRENT_MODE_TYPE)
35+
36+
expect(
37+
typeOf({
38+
$$typeof: is.Element,
39+
type: is.Fragment
40+
})
41+
).toBe(REACT_FRAGMENT_TYPE)
42+
43+
expect(
44+
typeOf({
45+
$$typeof: is.Element,
46+
type: is.Profiler
47+
})
48+
).toBe(REACT_PROFILER_TYPE)
49+
50+
expect(
51+
typeOf({
52+
$$typeof: is.Element,
53+
type: is.StrictMode
54+
})
55+
).toBe(REACT_STRICT_MODE_TYPE)
56+
57+
expect(
58+
typeOf({
59+
$$typeof: is.Element,
60+
type: is.Suspense
61+
})
62+
).toBe(REACT_SUSPENSE_TYPE)
5163
})
5264
})

src/__tests__/element.test.js

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,38 @@ describe('typeOf', () => {
2020
it('correctly identifies all elements', () => {
2121
expect(typeOf({})).toBe(undefined)
2222

23-
expect(typeOf({
24-
$$typeof: is.Portal
25-
})).toBe(REACT_PORTAL_TYPE)
23+
expect(
24+
typeOf({
25+
$$typeof: is.Portal
26+
})
27+
).toBe(REACT_PORTAL_TYPE)
2628

27-
expect(typeOf({
28-
$$typeof: is.Element,
29-
type: is.ConcurrentMode
30-
})).toBe(REACT_CONCURRENT_MODE_TYPE)
29+
expect(
30+
typeOf({
31+
$$typeof: is.Element,
32+
type: is.ConcurrentMode
33+
})
34+
).toBe(REACT_CONCURRENT_MODE_TYPE)
3135

32-
expect(typeOf({
33-
$$typeof: is.Element,
34-
type: is.Fragment
35-
})).toBe(REACT_FRAGMENT_TYPE)
36+
expect(
37+
typeOf({
38+
$$typeof: is.Element,
39+
type: is.Fragment
40+
})
41+
).toBe(REACT_FRAGMENT_TYPE)
3642

37-
expect(typeOf({
38-
$$typeof: is.Element,
39-
type: is.Profiler
40-
})).toBe(REACT_PROFILER_TYPE)
43+
expect(
44+
typeOf({
45+
$$typeof: is.Element,
46+
type: is.Profiler
47+
})
48+
).toBe(REACT_PROFILER_TYPE)
4149

42-
expect(typeOf({
43-
$$typeof: is.Element,
44-
type: is.StrictMode
45-
})).toBe(REACT_STRICT_MODE_TYPE)
50+
expect(
51+
typeOf({
52+
$$typeof: is.Element,
53+
type: is.StrictMode
54+
})
55+
).toBe(REACT_STRICT_MODE_TYPE)
4656
})
4757
})

src/__tests__/suspense.test.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ describe('renderPrepass', () => {
1515
describe('function components', () => {
1616
it('supports suspending subtrees', () => {
1717
const value = {}
18-
const getValue = jest.fn()
19-
.mockImplementationOnce(() => { throw Promise.resolve() })
18+
const getValue = jest
19+
.fn()
20+
.mockImplementationOnce(() => {
21+
throw Promise.resolve()
22+
})
2023
.mockImplementationOnce(() => value)
2124

2225
const Inner = jest.fn(props => {
@@ -54,8 +57,11 @@ describe('renderPrepass', () => {
5457
})
5558

5659
it('preserves state correctly across suspensions', () => {
57-
const getValue = jest.fn()
58-
.mockImplementationOnce(() => { throw Promise.resolve() })
60+
const getValue = jest
61+
.fn()
62+
.mockImplementationOnce(() => {
63+
throw Promise.resolve()
64+
})
5965
.mockImplementation(() => 'test')
6066

6167
const Inner = jest.fn(props => {
@@ -84,7 +90,9 @@ describe('renderPrepass', () => {
8490
})
8591

8692
it('ignores thrown non-promises', () => {
87-
const Outer = () => { throw new Error('test') }
93+
const Outer = () => {
94+
throw new Error('test')
95+
}
8896
const render$ = renderPrepass(<Outer />)
8997
expect(render$).rejects.toThrow('test')
9098
})
@@ -95,7 +103,7 @@ describe('renderPrepass', () => {
95103

96104
const visitor = jest.fn(element => {
97105
if (element.type === Inner) return Promise.resolve()
98-
});
106+
})
99107

100108
const render$ = renderPrepass(<Outer />, visitor)
101109

@@ -117,14 +125,19 @@ describe('renderPrepass', () => {
117125
describe('class components', () => {
118126
it('supports suspending subtrees', () => {
119127
const value = {}
120-
const getValue = jest.fn()
121-
.mockImplementationOnce(() => { throw Promise.resolve() })
128+
const getValue = jest
129+
.fn()
130+
.mockImplementationOnce(() => {
131+
throw Promise.resolve()
132+
})
122133
.mockImplementationOnce(() => value)
123134

124135
const Inner = jest.fn(props => expect(props.value).toBe(value))
125136

126137
class Outer extends Component {
127-
render() { return <Inner value={getValue()} /> }
138+
render() {
139+
return <Inner value={getValue()} />
140+
}
128141
}
129142

130143
const render$ = renderPrepass(<Outer />)
@@ -144,7 +157,9 @@ describe('renderPrepass', () => {
144157

145158
it('ignores thrown non-promises', () => {
146159
class Outer extends Component {
147-
render() { throw new Error('test') }
160+
render() {
161+
throw new Error('test')
162+
}
148163
}
149164

150165
const render$ = renderPrepass(<Outer />)
@@ -155,15 +170,17 @@ describe('renderPrepass', () => {
155170
const Inner = jest.fn(() => null)
156171

157172
class Outer extends Component {
158-
render() { return <Inner /> }
173+
render() {
174+
return <Inner />
175+
}
159176
}
160177

161178
const visitor = jest.fn((element, instance) => {
162179
if (element.type === Outer) {
163180
expect(instance).toEqual(expect.any(Outer))
164181
return Promise.resolve()
165182
}
166-
});
183+
})
167184

168185
const render$ = renderPrepass(<Outer />, visitor)
169186

@@ -200,7 +217,7 @@ describe('renderPrepass', () => {
200217
instance.updater.enqueueForceUpdate(instance)
201218
instance.updater.enqueueReplaceState(instance, newState)
202219
}
203-
});
220+
})
204221

205222
renderPrepass(<Outer />, visitor)
206223
expect(visitor).toHaveBeenCalledTimes(1)
@@ -315,7 +332,7 @@ describe('renderPrepass', () => {
315332
const TestC = jest.fn(() => {
316333
expect(useContext(Context)).toBe('c')
317334
if (!hasSuspended) {
318-
throw Promise.resolve().then(() => hasSuspended = true)
335+
throw Promise.resolve().then(() => (hasSuspended = true))
319336
}
320337

321338
return null
@@ -333,7 +350,7 @@ describe('renderPrepass', () => {
333350
<TestC />
334351
</Context.Provider>
335352
</Fragment>
336-
);
353+
)
337354

338355
const render$ = renderPrepass(<Wrapper />)
339356
expect(TestC).toHaveBeenCalledTimes(1)

src/__tests__/visitor.test.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
import React, { Component, Fragment, createContext, useContext, useState } from 'react'
1+
import React, {
2+
Component,
3+
Fragment,
4+
createContext,
5+
useContext,
6+
useState
7+
} from 'react'
28
import { createPortal } from 'react-dom'
39

4-
import { Dispatcher, clearCurrentContextMap, getCurrentContextMap } from '../internals'
10+
import {
11+
Dispatcher,
12+
clearCurrentContextMap,
13+
getCurrentContextMap
14+
} from '../internals'
515
import { visitElement } from '../visitor'
616

717
const {
@@ -24,15 +34,27 @@ const Noop = () => null
2434

2535
describe('visitElement', () => {
2636
it('walks Fragments', () => {
27-
const element = <Fragment><Noop />{null}<Noop /></Fragment>
37+
const element = (
38+
<Fragment>
39+
<Noop />
40+
{null}
41+
<Noop />
42+
</Fragment>
43+
)
2844
const children = visitElement(element, [], () => {})
2945
expect(children.length).toBe(2)
3046
expect(children[0].type).toBe(Noop)
3147
expect(children[1].type).toBe(Noop)
3248
})
3349

3450
it('walks DOM elements', () => {
35-
const element = <div><Noop />{null}<Noop /></div>
51+
const element = (
52+
<div>
53+
<Noop />
54+
{null}
55+
<Noop />
56+
</div>
57+
)
3658
const children = visitElement(element, [], () => {})
3759
expect(children.length).toBe(2)
3860
expect(children[0].type).toBe(Noop)
@@ -45,9 +67,7 @@ describe('visitElement', () => {
4567

4668
const makeChild = value => (
4769
<Context.Provider value={value}>
48-
<Context.Consumer>
49-
{leaf}
50-
</Context.Consumer>
70+
<Context.Consumer>{leaf}</Context.Consumer>
5171
</Context.Provider>
5272
)
5373

@@ -115,7 +135,7 @@ describe('visitElement', () => {
115135
})
116136

117137
it('renders class components with getDerivedStateFromProps', () => {
118-
const onUnmount = jest.fn();
138+
const onUnmount = jest.fn()
119139

120140
class Test extends Component {
121141
static getDerivedStateFromProps() {
@@ -136,7 +156,7 @@ describe('visitElement', () => {
136156
}
137157
}
138158

139-
const visitor = jest.fn();
159+
const visitor = jest.fn()
140160
const children = visitElement(<Test />, [], visitor)
141161

142162
expect(children.length).toBe(1)
@@ -147,15 +167,15 @@ describe('visitElement', () => {
147167
})
148168

149169
it('renders class components with componentWillMount', () => {
150-
['componentWillMount', 'UNSAFE_componentWillMount'].forEach(methodName => {
151-
const onUnmount = jest.fn();
170+
;['componentWillMount', 'UNSAFE_componentWillMount'].forEach(methodName => {
171+
const onUnmount = jest.fn()
152172

153173
class Test extends Component {
154174
constructor() {
155175
super()
156176

157177
this.state = { value: 'a' }
158-
this[methodName] = function () {
178+
this[methodName] = function() {
159179
this.setState({ value: 'b' })
160180
}
161181
}
@@ -214,7 +234,7 @@ describe('visitElement', () => {
214234
return <Noop>{value}</Noop>
215235
}
216236

217-
const visitor = jest.fn();
237+
const visitor = jest.fn()
218238
const children = visitElement(<Test />, [], visitor)
219239
expect(children.length).toBe(1)
220240
expect(children[0].type).toBe(Noop)

src/render/functionComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const mount = (
6969
props: DefaultProps,
7070
queue: Frame[],
7171
visitor: Visitor,
72-
element?: UserElement,
72+
element?: UserElement
7373
): Node => {
7474
setFirstHook(null)
7575
setCurrentIdentity(makeIdentity())

src/render/lazyComponent.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
const resolve = (type: LazyComponent): Promise<void> => {
1414
type._status = 0 /* PENDING */
1515

16-
return type._ctor()
16+
return type
17+
._ctor()
1718
.then(Component => {
1819
if (typeof Component === 'function') {
1920
type._result = Component
@@ -69,10 +70,7 @@ export const mount = (
6970
return render(type, props, queue)
7071
}
7172

72-
export const update = (
73-
queue: Frame[],
74-
frame: LazyFrame
75-
): Node => {
73+
export const update = (queue: Frame[], frame: LazyFrame): Node => {
7674
setCurrentIdentity(null)
7775
setCurrentContextMap(frame.contextMap)
7876
return render(frame.type, frame.props, queue)

0 commit comments

Comments
 (0)