From 73f135adb4d2c4fa02bffb037fc3df6909ca152c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Aaberg?= Date: Mon, 11 Dec 2017 22:06:04 +0100 Subject: [PATCH] Add more test cases for no-access-state-in-setstate --- .../lib/rules/no-access-state-in-setstate.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/lib/rules/no-access-state-in-setstate.js b/tests/lib/rules/no-access-state-in-setstate.js index 2ff75352d3..784c6f6ed7 100644 --- a/tests/lib/rules/no-access-state-in-setstate.js +++ b/tests/lib/rules/no-access-state-in-setstate.js @@ -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: [{ @@ -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) {',