- Notifications
You must be signed in to change notification settings - Fork 153
Closed
Labels
Description
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.
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:
But wrapping it in an if statement gets the problem back:
This seems related to the fact that CallExpression
is not a direct child of the function body, so we are not detecting this correctly.
douglasjunior and sjarvaFernandaKPeron