Skip to content

Commit

Permalink
fix: support identifiers in to-be-undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Dec 6, 2017
1 parent e3f8884 commit c35f2a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion rules/__tests__/prefer_to_be_null.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const rules = require('../../').rules;
const ruleTester = new RuleTester();

ruleTester.run('prefer_to_be_null', rules['prefer-to-be-null'], {
valid: ['expect(null).toBeNull();', 'expect(null).toEqual();'],
valid: [
'expect(null).toBeNull();',
'expect(null).toEqual();',
"expect(something).toEqual('a string');",
],

invalid: [
{
Expand Down
4 changes: 4 additions & 0 deletions rules/__tests__/prefer_to_be_undefined.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ ruleTester.run('prefer_to_be_undefined', rules['prefer-to-be-undefined'], {
'expect(true).not.toBeUndefined();',
'expect({}).toEqual({});',
'expect(null).toEqual(null);',
'expect(something).toBe(somethingElse)',
'expect(something).toEqual(somethingElse)',
'expect(something).not.toBe(somethingElse)',
'expect(something).not.toEqual(somethingElse)',
],

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,8 +27,10 @@ const expectToBeCase = (node, arg) =>
expectCase(node) &&
methodName(node) === 'toBe' &&
argument(node) &&
argument(node).value === arg &&
(arg === null || argument(node).name);
((argument(node).type === 'Literal' &&
argument(node).value === null &&
arg === null) ||
(argument(node).name === 'undefined' && arg === undefined));

const expectNotToBeCase = (node, arg) =>
expectNotCase(node) &&
Expand All @@ -42,8 +44,10 @@ const expectToEqualCase = (node, arg) =>
expectCase(node) &&
methodName(node) === 'toEqual' &&
argument(node) &&
argument(node).value === arg &&
(arg === null || argument(node).name);
((argument(node).type === 'Literal' &&
argument(node).value === null &&
arg === null) ||
(argument(node).name === 'undefined' && arg === undefined));

const expectNotToEqualCase = (node, arg) =>
expectNotCase(node) &&
Expand Down

0 comments on commit c35f2a1

Please sign in to comment.