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 from no-unnecessary-act #686

Open
Belco90 opened this issue Oct 31, 2022 Discussed in #685 · 0 comments
Open

False positive from no-unnecessary-act #686

Belco90 opened this issue Oct 31, 2022 Discussed in #685 · 0 comments
Labels
bug Something isn't working

Comments

@Belco90
Copy link
Member

Belco90 commented Oct 31, 2022

Discussed in #685

Originally posted by douglasjunior October 28, 2022
In one test case we called a function within ACT that ESLint indicates is a testing-library function, but is not.

image

And dismissCallback need to be wrapped with act because it dispatches a state update to close the AlertModal.

  it('should not auto close modal with autoDismiss=false', async () => {
    const mockOnDismiss = jest.fn();

    let dismissCallback: undefined | (() => void);

    const tree = render(
      <AlertModal
        visible
        title="Title"
        description="Lorem ipsum is placeholder text commonly used in the graphic"
        primaryButtonName="Primary Action"
        secondaryButtonName="Secondary Action"
        autoDismiss={false}
        onPressSecondary={event => {
          dismissCallback = event.dismiss;
        }}
        onDismiss={mockOnDismiss}
      />,
    );

    const buttonInstance = tree.getByTestId('alert-modal-secondary-button');
    fireEvent.press(buttonInstance);

    expect(dismissCallback).toBeDefined();

    expect(mockOnDismiss).not.toBeCalled();

    act(() => {
      dismissCallback?.();
    });

    expect(mockOnDismiss).toHaveBeenCalled();

This has been confirmed as a false positive. Removing the optional chaining from dismissCallback call fixes the issue:

imagen

But wrapping it in an if statement gets the problem back:

imagen

This seems related to the fact that CallExpression is not a direct child of the function body, so we are not detecting this correctly.

@Belco90 Belco90 added the bug Something isn't working label Oct 31, 2022
@Belco90 Belco90 changed the title False negative from no-unnecessary-act False positive from no-unnecessary-act Oct 31, 2022
@Belco90 Belco90 assigned Belco90 and unassigned Belco90 Dec 23, 2022
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

1 participant