Skip to content

Commit

Permalink
Add more test cases for no-access-state-in-setstate
Browse files Browse the repository at this point in the history
  • Loading branch information
jaaberg committed Dec 11, 2017
1 parent f6e4c89 commit 73f135a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/lib/rules/no-access-state-in-setstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ ruleTester.run('no-access-state-in-setstate', rule, {
});
`,
parserOptions: parserOptions
}, {
code: [
'var Hello = React.createClass({',
' onClick: function() {',
' var nextValueNotUsed = this.state.value + 1',
' var nextValue = 2',
' this.setState({value: nextValue})',
' }',
'});'
].join('\n'),
parserOptions: parserOptions
}],

invalid: [{
Expand Down Expand Up @@ -103,6 +114,19 @@ ruleTester.run('no-access-state-in-setstate', rule, {
errors: [{
message: 'Use callback in setState when referencing the previous state.'
}]
}, {
code: [
'var Hello = React.createClass({',
' onClick: function() {',
' var {state} = this',
' this.setState({value: state.value + 1})',
' }',
'});'
].join('\n'),
parserOptions: parserOptions,
errors: [{
message: 'Use callback in setState when referencing the previous state.'
}]
}, {
code: [
'function nextState(state) {',
Expand Down

0 comments on commit 73f135a

Please sign in to comment.