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

Add prefer-spy-on rule #191

Merged
merged 4 commits into from
Nov 3, 2018
Merged

Add prefer-spy-on rule #191

merged 4 commits into from
Nov 3, 2018

Conversation

hanneslund
Copy link
Contributor

Feedback welcome, especially the docs and error message.

Closes #185

@SimenB SimenB requested a review from macklinu October 28, 2018 16:17
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

I like this! Left some nits, but overall LGTM

docs/rules/prefer-spy-on.md Outdated Show resolved Hide resolved
rules/__tests__/prefer-spy-on.test.js Outdated Show resolved Hide resolved
rules/__tests__/prefer-spy-on.test.js Show resolved Hide resolved
docs/rules/prefer-spy-on.md Show resolved Hide resolved
rules/prefer-spy-on.js Outdated Show resolved Hide resolved
output: "jest.spyOn(Date, 'now')",
},
{
code: "obj['prop' + 1] = jest['fn']()",
Copy link
Member

Choose a reason for hiding this comment

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

could you add a test using template strings as well?

Copy link
Contributor Author

@hanneslund hanneslund Nov 1, 2018

Choose a reason for hiding this comment

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

I added a test for window[`${name}`] = jest.fn(). window.name = jest[`fn`]() doesn't trigger a warning though because i'm using util.getNodeName which ignores TemplateLiterals.

Another test, that I know of, that doesn't handle TemplateLiterals is no-identical-title. This doesn't trigger warning:

test("name", () =>{})
test(`name`, () => {})

Should they though?

Copy link
Member

@SimenB SimenB Nov 1, 2018

Choose a reason for hiding this comment

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

Yeah, I think they should. At least if there's no concatenation or interpolation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a TemplateLiteral case to util.getNodeName. This also adds TemplateLiteral support for some other rules which i could add tests for. But maybe in another pull request?

Copy link
Member

Choose a reason for hiding this comment

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

Separate PR fleshing out other tests would be great!

@SimenB SimenB merged commit ca12f6a into jest-community:master Nov 3, 2018
@SimenB
Copy link
Member

SimenB commented Nov 3, 2018

@hanneslund hmm, on master, it says line 112 is not covered by tests, mind checking it out?

@hanneslund
Copy link
Contributor Author

@SimenB yeah sure!

@SimenB
Copy link
Member

SimenB commented Nov 3, 2018

I added 1047c9c as a quickfix

@hanneslund hanneslund deleted the prefer-spy-on branch November 3, 2018 12:37
SimenB pushed a commit that referenced this pull request Nov 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants