-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Failing test: Class callback fired multiple times
Happens during a rebase (low priority update followed by high priority update). The high priority callback gets fired twice.
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/react-reconciler/src/__tests__/ReactClassSetStateCallback-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,47 @@ | ||
let React; | ||
let ReactNoop; | ||
let Scheduler; | ||
|
||
describe('ReactClassSetStateCallback', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
|
||
React = require('react'); | ||
ReactNoop = require('react-noop-renderer'); | ||
Scheduler = require('scheduler'); | ||
}); | ||
|
||
function Text({text}) { | ||
Scheduler.unstable_yieldValue(text); | ||
return text; | ||
} | ||
|
||
test('regression: setState callback (2nd arg) should only fire once, even after a rebase', async () => { | ||
let app; | ||
class App extends React.Component { | ||
state = {step: 0}; | ||
render() { | ||
app = this; | ||
return <Text text={this.state.step} />; | ||
} | ||
} | ||
|
||
const root = ReactNoop.createRoot(); | ||
await ReactNoop.act(async () => { | ||
root.render(<App />); | ||
}); | ||
expect(Scheduler).toHaveYielded([0]); | ||
|
||
await ReactNoop.act(async () => { | ||
app.setState({step: 1}, () => | ||
Scheduler.unstable_yieldValue('Callback 1'), | ||
); | ||
ReactNoop.flushSync(() => { | ||
app.setState({step: 2}, () => | ||
Scheduler.unstable_yieldValue('Callback 2'), | ||
); | ||
}); | ||
}); | ||
expect(Scheduler).toHaveYielded([2, 'Callback 2', 2, 'Callback 1']); | ||
}); | ||
}); |