Skip to content

Lint RenderResult when returned from function #141

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

Closed
HaveSpacesuit opened this issue May 18, 2020 · 9 comments
Closed

Lint RenderResult when returned from function #141

HaveSpacesuit opened this issue May 18, 2020 · 9 comments
Labels
bug Something isn't working
Milestone

Comments

@HaveSpacesuit
Copy link

When returning a RenderResult from a function, some destructured methods are caught by the linter, but others aren't.

it('displays a loader', () => {
  const { getByText, debug } = render(<MyLoader />);
  getByText('Loading'); // Caught by linter
  debug(); // Caught by linter
});

it('displays a loader', () => {
  function renderLoader(): RenderResult {
    return render(<MyLoader />);
  }

  const { getByText, debug } = renderLoader();
  getByText('Loading'); // Caught by linter
  debug(); // Linter doesn't care
});
@Belco90 Belco90 added the bug Something isn't working label May 19, 2020
@Belco90
Copy link
Member

Belco90 commented May 19, 2020

Hey Eric! Thanks for opening an issue. It seems some rules are not checking properly those methods if not coming directly from testing library.

@timdeschryver
Copy link
Member

Which rule is this? 👀
I'm thinking this is prefer-presence-queries, and it expect queries to be used from screen.
Imho this is correct.

@Belco90
Copy link
Member

Belco90 commented May 19, 2020

Well, the comment in the original description code indicating something not being linted is a debug method. I guess this refers to no-debug rule. @HaveSpacesuit please correct me if I'm wrong.

@timdeschryver
Copy link
Member

Oh my bad, I miss-read the snippet.

@thomaslombart
Copy link
Collaborator

thomaslombart commented Jul 20, 2020

I'm not sure that's a bug. @HaveSpacesuit, have you tried setting up the renderFunctions option when configuring the no-debug rule?

You can do it this way:

rules: {
  "testing-library/no-debug": ["error", { "renderFunctions": ["renderLoader"] }],
}

If the getByText query is caught by the linter in the renderLoader example, it's probably because of the prefer-screen-queries rule.

@Belco90
Copy link
Member

Belco90 commented Jul 20, 2020

I think this one should be fixed when #198 is released.

@HaveSpacesuit
Copy link
Author

The "testing-library/no-debug": ["error", { "renderFunctions": ["renderLoader"] }] rule doesn't seem to make any difference. The getByText is caught with the prefer-screen-queries rule whether or not it is destructured directly from render or from a function returning RenderResult, but the no-debug rule is not caught.

@Belco90
Copy link
Member

Belco90 commented Jul 27, 2020

Everything related to custom error render methods will change and should be fixed when #198 is released with v4.

@Belco90
Copy link
Member

Belco90 commented Apr 11, 2021

This should be fixed on v4.0.0

The release is available on:

@Belco90 Belco90 closed this as completed Apr 11, 2021
@MichaelDeBoey MichaelDeBoey added this to the v4 milestone Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants