Skip to content

Commit

Permalink
[Tests] no-access-state-in-setstate: add passing tests
Browse files Browse the repository at this point in the history
Closes #1931
  • Loading branch information
ljharb committed Jul 28, 2020
1 parent f0ff971 commit 253a62a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/lib/rules/no-access-state-in-setstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

const RuleTester = require('eslint').RuleTester;
const rule = require('../../../lib/rules/no-access-state-in-setstate');
const parsers = require('../../helpers/parsers');

const parserOptions = {
ecmaVersion: 2018,
Expand Down Expand Up @@ -102,6 +103,23 @@ ruleTester.run('no-access-state-in-setstate', rule, {
};
`,
parserOptions
}, {
code: `
class ComponentA extends React.Component {
state = {
greeting: 'hello',
};
myFunc = () => {
this.setState({ greeting: 'hi' }, () => this.doStuff());
};
doStuff = () => {
console.log(this.state.greeting);
};
}
`,
parser: parsers.BABEL_ESLINT,
}],

invalid: [{
Expand Down

0 comments on commit 253a62a

Please sign in to comment.