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

proposal: optional chaining is conditionality and should violate no-conditional-in-test #643

Closed
jroru opened this issue Jan 29, 2025 · 1 comment

Comments

@jroru
Copy link

jroru commented Jan 29, 2025

This code currently violates no-conditional-in-test

describe("suite", () => {
  it("clicking button does something", () => {
    const button: Button | null = findButton();
    if (button) {
      button.click();
    }
    expect(someCallback).toHaveBeenCalled();
  });
});

Whereas this code does not:

describe("suite", () => {
  it("clicking button does something", () => {
    const button: Button | null = findButton();
    button?.click();
    expect(someCallback).toHaveBeenCalled();
  });
});

Happy to help on a PR if there is consensus.

@veritem
Copy link
Member

veritem commented Feb 2, 2025

i agree, a pr is welcome!

@veritem veritem closed this as completed Feb 14, 2025
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

No branches or pull requests

2 participants