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

False-positive jest/no-disabled-tests #775

Closed
fabb opened this issue Mar 6, 2021 · 7 comments
Closed

False-positive jest/no-disabled-tests #775

fabb opened this issue Mar 6, 2021 · 7 comments

Comments

@fabb
Copy link

fabb commented Mar 6, 2021

In a non-test file (trackingXiti.ts), I have a function like this:

const mapPageViewEventName = (...) => {
    ....
    const map = xitiViewMap(...)
    ...
}

The rule warns about the line with the xitiViewMap function, probably because it starts with xit.

  1. Shouldn't the jest rules only run on *.test.{js,tsx?} files?
  2. The rule should match xit( and not xitSomethingElse(
@G-Rath
Copy link
Collaborator

G-Rath commented Mar 6, 2021

Shouldn't the jest rules only run on *.test.{js,tsx?} files?

No, because jest doesn't require you to name your test files like that - you should be configuring eslint to only apply eslint-plugin-jest to your test files using overrides.

The rule should match xit( and not xitSomethingElse(

Correct - it's because our matcher is incorrect, I'll have a PR up shortly.

@fabb
Copy link
Author

fabb commented Mar 6, 2021

Would it be possible that the plugin reads jest.config.js to know which files it should consider?

@G-Rath
Copy link
Collaborator

G-Rath commented Mar 6, 2021

We do hope to read the config one day to enhance the rules - see here for why that's currently not possible.

However, I don't think we'd do that for determining what files to run on, as that is exactly what you're meant to be using overrides for and some of our rules don't require being rule on files that jest runs as tests (i.e test helpers).

@fabb
Copy link
Author

fabb commented Mar 6, 2021

I‘m not completely sure how I should use overrides here, currently I‘m just using an /* eslint-disable jest/no-disabled-tests */ rule at the top of the (non-test) file. Would be nice If I could somehow generally declare which rules to enable for which files without having to specify it in the files themselves.

@G-Rath
Copy link
Collaborator

G-Rath commented Mar 6, 2021

Would be nice If I could somehow generally declare which rules to enable for which files without having to specify it in the files themselves.

That's what exactly overrides is for :)

Here's one of my projects that uses overrides to apply the eslint-plugin-jest rules only to test files (via applying my company's jest shared config).

@fabb
Copy link
Author

fabb commented Mar 6, 2021

Ah nice, thanks! The first link above to overrides confused me.

@G-Rath
Copy link
Collaborator

G-Rath commented Mar 6, 2021

No problem! it is currently a bit confusing - iirc the new config system that'll be coming over the next year or so includes refactoring the config to be "override based" which should be better - so instead of having rules & overrides, the config is more like having overrides as the top-level, so it'll be a lot more obvious and natural to point your rules at specific files via paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants