question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[jest/valid-describe] "First argument must be name" incorrect error

See original GitHub issue
import { MY_REDUX_ACTION } from "./actions";

describe(MY_REDUX_ACTION, () => {
	//...
});

We’re getting the error “First argument must be name” [jest/valid-describe]. This appears to be because the first argument is a variable instead of a string.

However, our use case is testing redux store actions. Those action types are exported as strings. We use those strings to name our jest tests.

This seems like a reasonable situation that is incorrectly marked as wrong.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:9

github_iconTop GitHub Comments

6reactions
dashmugcommented, Apr 4, 2019

Workaround…

describe(`${MY_REDUX_ACTION}`, () => {
	//...
});
4reactions
thisissamicommented, Jun 28, 2019

Hi - just chiming in here, and copying what I wrote in PR #253. tl;dr - this feels like a code smell, and this rule should probably be removed completely. It’s trying to typecheck instead of lint. Quoting myself:

Seeing as how this hasn’t been merged in yet, I’m just gonna chime in with a different opinion: the linter should not enforce a particular form of strings, period. The first argument for a describe should be a string, and any valid way of generating a string there should be valid. If there is no way to do this, then this should not be the linter’s responsibility, and this rule should be completely removed.

If people want typechecking, they can use typescript, which jest fully supports; it will complain if you don’t pass in a string.

If the community insists on this being a rule for the linter, then the message that it expresses should make it really clear that this might not actually be an issue. E.g. instead of

First argument must be name

it could be

First argument must be name. Also if you are using a string variable or function that returns a string, then please ignore this message.

^if something like that is needed, then… it’s a code smell and probably shouldn’t be something the linter handles.

My $.02.

EDIT: the “catching async callbacks” aspect of this rule, however, is great.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint: Definition for rule 'jest/valid-describe' was not found ...
The rule was renamed to valid-describe-callback in eslint-plugin-jest@25.0.0 , which you updated past. You will need to rename any config ...
Read more >
[R] Error: Invalid First Argument in DPlyr
You need to divide and conquer... find out which step is breaking the pipe by terminating it early at various points and if...
Read more >
eslint-config-canonical - npm
Rule CN AB GG SD XO @babel/new‑cap ❌ 👻 👻 👻 👻 @babel/no‑invalid‑this 🚨 👻 👻 👻 👻 @babel/no‑unused‑expressions 🚨 👻 👻 👻 👻
Read more >
eslint-plugin-jest @ 22.5.1 .. 22.6.0 - Package Diff
+The plugin looks at the literal function names within test code, so will not ... + 'jest/valid-describe': 'error', ... + arguments: [first, second]....
Read more >
https://raw.githubusercontent.com/CodingZeal/eslin...
([#59](https://github.com/CodingZeal/eslint-config-zeal/pull/59)) - Use default configuration for the `react/jsx-first-prop-new-line` rule ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found