Skip to content

Commit 4a6d486

Browse files
G-RathSimenB
authored andcommitted
fix: check method(node) returns truthy before trying to using results (#358)
Fixes #357
1 parent 098219b commit 4a6d486

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

src/rules/__tests__/prefer-to-be-null.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ruleTester.run('prefer-to-be-null', rule, {
1717
'expect("a string").not.toMatchSnapshot();',
1818
"expect(something).toEqual('a string');",
1919
'expect(null).toBe',
20+
'expect("something");',
2021
],
2122

2223
invalid: [

src/rules/__tests__/prefer-to-be-undefined.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ruleTester.run('prefer-to-be-undefined', rule, {
1414
'expect(something).not.toBe(somethingElse)',
1515
'expect(something).not.toEqual(somethingElse)',
1616
'expect(undefined).toBe',
17+
'expect("something");',
1718
],
1819

1920
invalid: [

src/rules/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ export const method = node => node.parent.property;
8787

8888
export const method2 = node => node.parent.parent.property;
8989

90-
const methodName = node => method(node).name;
90+
const methodName = node => method(node) && method(node).name;
9191

92-
const methodName2 = node => method2(node).name;
92+
const methodName2 = node => method2(node) && method2(node).name;
9393

9494
export const argument = node =>
9595
node.parent.parent.arguments && node.parent.parent.arguments[0];

0 commit comments

Comments
 (0)