-
Notifications
You must be signed in to change notification settings - Fork 47.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression tests for noop renderer
- Loading branch information
Showing
2 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
packages/react-reconciler/src/__tests__/ReactIncrementalUpdatesMinimalism-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
* @jest-environment node | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let React; | ||
let ReactNoop; | ||
|
||
describe('ReactIncrementalUpdatesMinimalism', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
React = require('react'); | ||
ReactNoop = require('react-noop-renderer'); | ||
}); | ||
|
||
it('should render a simple component', () => { | ||
function Child() { | ||
return <div>Hello World</div>; | ||
} | ||
|
||
function Parent() { | ||
return <Child />; | ||
} | ||
|
||
ReactNoop.render(<Parent />); | ||
expect(ReactNoop.flushWithHostCounters()).toEqual({ | ||
hostDiffCounter: 0, | ||
hostUpdateCounter: 0, | ||
}); | ||
|
||
ReactNoop.render(<Parent />); | ||
expect(ReactNoop.flushWithHostCounters()).toEqual({ | ||
hostDiffCounter: 1, | ||
hostUpdateCounter: 1, | ||
}); | ||
}); | ||
|
||
it('should not diff referentially equal host elements', () => { | ||
function Leaf(props) { | ||
return ( | ||
<span> | ||
hello | ||
<b /> | ||
{props.name} | ||
</span> | ||
); | ||
} | ||
|
||
const constEl = ( | ||
<div> | ||
<Leaf name="world" /> | ||
</div> | ||
); | ||
|
||
function Child() { | ||
return constEl; | ||
} | ||
|
||
function Parent() { | ||
return <Child />; | ||
} | ||
|
||
ReactNoop.render(<Parent />); | ||
expect(ReactNoop.flushWithHostCounters()).toEqual({ | ||
hostDiffCounter: 0, | ||
hostUpdateCounter: 0, | ||
}); | ||
|
||
ReactNoop.render(<Parent />); | ||
expect(ReactNoop.flushWithHostCounters()).toEqual({ | ||
hostDiffCounter: 0, | ||
hostUpdateCounter: 0, | ||
}); | ||
}); | ||
|
||
it('should not diff parents of setState targets', () => { | ||
let childInst; | ||
|
||
function Leaf(props) { | ||
return ( | ||
<span> | ||
hello | ||
<b /> | ||
{props.name} | ||
</span> | ||
); | ||
} | ||
|
||
class Child extends React.Component { | ||
state = {name: 'Batman'}; | ||
render() { | ||
childInst = this; | ||
return ( | ||
<div> | ||
<Leaf name={this.state.name} /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
function Parent() { | ||
return ( | ||
<section> | ||
<div> | ||
<Leaf name="world" /> | ||
<Child /> | ||
<Leaf name="world" /> | ||
</div> | ||
</section> | ||
); | ||
} | ||
|
||
ReactNoop.render(<Parent />); | ||
expect(ReactNoop.flushWithHostCounters()).toEqual({ | ||
hostDiffCounter: 0, | ||
hostUpdateCounter: 0, | ||
}); | ||
|
||
childInst.setState({name: 'Robin'}); | ||
expect(ReactNoop.flushWithHostCounters()).toEqual({ | ||
// Child > div | ||
// Child > Leaf > span | ||
// Child > Leaf > span > b | ||
hostDiffCounter: 3, | ||
// Child > div | ||
// Child > Leaf > span | ||
// Child > Leaf > span > b | ||
// Child > Leaf > span > #text | ||
hostUpdateCounter: 4, | ||
}); | ||
|
||
ReactNoop.render(<Parent />); | ||
expect(ReactNoop.flushWithHostCounters()).toEqual({ | ||
// Parent > section | ||
// Parent > section > div | ||
// Parent > section > div > Leaf > span | ||
// Parent > section > div > Leaf > span > b | ||
// Parent > section > div > Child > div | ||
// Parent > section > div > Child > div > Leaf > span | ||
// Parent > section > div > Child > div > Leaf > span > b | ||
// Parent > section > div > Leaf > span | ||
// Parent > section > div > Leaf > span > b | ||
hostDiffCounter: 9, | ||
hostUpdateCounter: 9, | ||
}); | ||
}); | ||
}); |