Skip to content

Commit

Permalink
fix: add null guards on argument selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
xfumihiro authored and SimenB committed Dec 5, 2017
1 parent 775e75d commit cb2d9ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions rules/__tests__/prefer_to_be_undefined.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ ruleTester.run('prefer_to_be_undefined', rules['prefer-to-be-undefined'], {
valid: [
'expect(undefined).toBeUndefined();',
'expect(true).not.toBeUndefined();',
'expect({}).toEqual({});',
'expect(null).toEqual(null);',
],

invalid: [
Expand Down
12 changes: 8 additions & 4 deletions rules/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,30 @@ const expectToBeCase = (node, arg) =>
expectCase(node) &&
methodName(node) === 'toBe' &&
argument(node) &&
argument(node).value === arg;
argument(node).value === arg &&
(arg === null || argument(node).name);

const expectNotToBeCase = (node, arg) =>
expectNotCase(node) &&
methodName2(node) === 'toBe' &&
argument2(node) &&
argument2(node).value === arg;
argument2(node).value === arg &&
(arg === null || argument2(node).name);

const expectToEqualCase = (node, arg) =>
!(expectNotCase(node) || expectResolveCase(node) || expectRejectCase(node)) &&
expectCase(node) &&
methodName(node) === 'toEqual' &&
argument(node) &&
argument(node).value === arg;
argument(node).value === arg &&
(arg === null || argument(node).name);

const expectNotToEqualCase = (node, arg) =>
expectNotCase(node) &&
methodName2(node) === 'toEqual' &&
argument2(node) &&
argument2(node).value === arg;
argument2(node).value === arg &&
(arg === null || argument2(node).name);

const expectToBeUndefinedCase = node =>
!(expectNotCase(node) || expectResolveCase(node) || expectRejectCase(node)) &&
Expand Down

0 comments on commit cb2d9ca

Please sign in to comment.