Skip to content

Commit 7c7c772

Browse files
authored
Fix: prefer-output-null crashes, when a test case is not object. (#22)
* Fix: prefer-output-null crashes, when a test case is not object. * Chore: add valid test.
1 parent 93bd142 commit 7c7c772

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/rules/prefer-output-null.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ module.exports = {
4040
* @returns {Node} found node; if not found, return null;
4141
*/
4242
function getTestInfo (key) {
43-
const res = test.properties.filter(item => item.key.name === key);
44-
return res.length ? res[res.length - 1] : null;
43+
if (test.type === 'ObjectExpression') {
44+
const res = test.properties.filter(item => item.key.name === key);
45+
return res.length ? res[res.length - 1] : null;
46+
}
47+
return key === 'code' ? test : null;
4548
}
4649

4750
const code = getTestInfo('code');

tests/lib/rules/prefer-output-null.js

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ ruleTester.run('prefer-output-null', rule, {
3737
]
3838
});
3939
`,
40+
`
41+
new RuleTester().run('foo', bar, {
42+
valid: [
43+
'foo'
44+
],
45+
invalid: []
46+
});
47+
`,
48+
4049
],
4150

4251
invalid: [

0 commit comments

Comments
 (0)