Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to-have-length when there are no argument properties #6

Merged
merged 3 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion rules/__tests__/prefer_to_have_length.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_have_length', rules['prefer-to-have-length'], {
valid: ['expect(files).toHaveLength(1);', "expect(files.name).toBe('file');"],
valid: [
'expect(files).toHaveLength(1);',
"expect(files.name).toBe('file');",
'expect(result).toBe(true);',
],

invalid: [
{
Expand Down
6 changes: 5 additions & 1 deletion rules/prefer_to_have_length.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ module.exports = context => {
const argumentObject = node.arguments[0].object;
const argumentProperty = node.arguments[0].property;

if (propertyName === 'toBe' && argumentProperty.name === 'length') {
if (
argumentProperty &&
propertyName === 'toBe' &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a nit, can we switch these two lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, gotcha

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being indirect :D

argumentProperty.name === 'length'
) {
const propertyDot = context
.getSourceCode()
.getFirstTokenBetween(
Expand Down