Skip to content

Commit 73f135a

Browse files
committed
Add more test cases for no-access-state-in-setstate
1 parent f6e4c89 commit 73f135a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/lib/rules/no-access-state-in-setstate.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ ruleTester.run('no-access-state-in-setstate', rule, {
6464
});
6565
`,
6666
parserOptions: parserOptions
67+
}, {
68+
code: [
69+
'var Hello = React.createClass({',
70+
' onClick: function() {',
71+
' var nextValueNotUsed = this.state.value + 1',
72+
' var nextValue = 2',
73+
' this.setState({value: nextValue})',
74+
' }',
75+
'});'
76+
].join('\n'),
77+
parserOptions: parserOptions
6778
}],
6879

6980
invalid: [{
@@ -103,6 +114,19 @@ ruleTester.run('no-access-state-in-setstate', rule, {
103114
errors: [{
104115
message: 'Use callback in setState when referencing the previous state.'
105116
}]
117+
}, {
118+
code: [
119+
'var Hello = React.createClass({',
120+
' onClick: function() {',
121+
' var {state} = this',
122+
' this.setState({value: state.value + 1})',
123+
' }',
124+
'});'
125+
].join('\n'),
126+
parserOptions: parserOptions,
127+
errors: [{
128+
message: 'Use callback in setState when referencing the previous state.'
129+
}]
106130
}, {
107131
code: [
108132
'function nextState(state) {',

0 commit comments

Comments
 (0)