Skip to content

Commit 5c6b355

Browse files
committed
Add contextTypes tests for prefer-stateless rule
1 parent 3148573 commit 5c6b355

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

tests/lib/rules/prefer-stateless-function.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,54 @@ ruleTester.run('prefer-stateless-function', rule, {
547547
errors: [{
548548
message: 'Component should be written as a pure function'
549549
}]
550-
550+
}, {
551+
code: `
552+
class Foo extends React.Component {
553+
static contextTypes = {
554+
foo: PropTypes.boolean
555+
}
556+
render() {
557+
const { foo } = this.context;
558+
return foo ? <div /> : null;
559+
}
560+
}
561+
`,
562+
parser: 'babel-eslint',
563+
errors: [{
564+
message: 'Component should be written as a pure function'
565+
}]
566+
}, {
567+
code: `
568+
class Foo extends React.Component {
569+
static get contextTypes() {
570+
return {
571+
foo: PropTypes.boolean
572+
};
573+
}
574+
render() {
575+
const { foo } = this.context;
576+
return foo ? <div /> : null;
577+
}
578+
}
579+
`,
580+
errors: [{
581+
message: 'Component should be written as a pure function'
582+
}]
583+
}, {
584+
code: `
585+
class Foo extends React.Component {
586+
render() {
587+
const { foo } = this.context;
588+
return foo ? <div /> : null;
589+
}
590+
}
591+
Foo.contextTypes = {
592+
foo: PropTypes.boolean
593+
};
594+
`,
595+
errors: [{
596+
message: 'Component should be written as a pure function'
597+
}]
551598
}
552599
]
553600
});

0 commit comments

Comments
 (0)