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

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

Closed
TheHolyWaffle opened this issue Nov 12, 2018 · 9 comments
Closed

Comments

@TheHolyWaffle
Copy link

TheHolyWaffle commented Nov 12, 2018

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.

@macklinu
Copy link
Collaborator

That use case makes sense - a PR to fix would be very welcome! 🙏

@dashmug
Copy link

dashmug commented Apr 4, 2019

Workaround...

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

@sergioregueira
Copy link

The same happens with classes and methods:

describe(Foo.name, () => {});
describe(Foo.build.name, () => {});

As @dashmug said, you can use templates until this issue is fixed:

describe(`{Foo.name}`, () => {});
describe(`{Foo.build.name}`, () => {});

@chrisdothtml
Copy link

PR here: #253

@kasvtv
Copy link

kasvtv commented May 30, 2019

This also occurs when one wants to linewrap using string concatenation like so:

describe('Lorem ipsum'
    + ' dolor sit amet', () => {

});

@thisissami
Copy link

thisissami commented Jun 27, 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.

@G-Rath
Copy link
Collaborator

G-Rath commented Aug 2, 2020

I'm going to close this as you can use ignoreTypeOfDescribeName to have valid-title ignore this pattern.

@G-Rath G-Rath closed this as completed Aug 2, 2020
@chrisbobbe
Copy link

Thanks for the tip! For posterity, I'll note that, as of version 23, it looks like valid-describe doesn't validate the title at all anymore; the way to do that (with whatever options you like) is in valid-title.

https://github.com/jest-community/eslint-plugin-jest/releases/tag/v23.0.0

@chrisbobbe
Copy link

I'm going to close this as you can use ignoreTypeOfDescribeName to have valid-title ignore this pattern.

Hmm, though it looks like this only applies to describe blocks, not test or it blocks. Looks like getting it to work in those other cases would be difficult: #470 (comment).

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

Successfully merging a pull request may close this issue.

10 participants