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

How to test Button disabled\enabled state? #4320

Open
stasmotorny opened this issue Feb 22, 2024 · 0 comments
Open

How to test Button disabled\enabled state? #4320

stasmotorny opened this issue Feb 22, 2024 · 0 comments
Labels
question Question related to the library, not an issue

Comments

@stasmotorny
Copy link

Hi, guys. I can't test Button state changes.
I have two inputs with validations, if user entered valid email and password and we have no errors login Button should become enabled otherwise it should be disabled.
When I'm testing my implementation on simulator everything works fine, btn becomes enabled or disabled as expected.
I want to write tests for this behaviour, but can't find a way to do it.
My test looks like this:

  it('Login button should be ENABLED if email and password are VALID', async () => {
    const user = userEvent.setup();

    const {getByTestId} = render(<App />);

    // Next two lines should simulate user input of valid data
    await user.type(getByTestId('EmailInput'), 'sd@gmail.cvom');
    await user.type(getByTestId('PasswordInput'), '12345');
    
    //After we simulated valid data input btn should become enabled
    const button = await screen.findByTestId('LoginBtn');
    expect(button).toBeEnabled();
  });

I was also trying to find some Button prop that defines enabled\disabled, but wasn't able to do it. accessibilityState.disabled is always true and accessible is also always true.

@stasmotorny stasmotorny added the question Question related to the library, not an issue label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question related to the library, not an issue
Projects
None yet
Development

No branches or pull requests

1 participant