Skip to content

Snackbar not auto closing #1278

@zeeshanjan82

Description

@zeeshanjan82
  • @testing-library/react version: 14.2.1
  • Testing Framework and version: Jest version 29.7.0
  • DOM Environment:

I am running the unit tests in react inside VS Code and using Google Chrome. I am using version 20.10.0 of Node.js
I am using react version 18.2.0

Relevant code or config:

  beforeEach(() => jest.useFakeTimers({ advanceTimers: true }));
  afterEach(() => {
    jest.useRealTimers();
  });

    const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });

    const wrongEmail = faker.internet.email();
    const emailInput = screen.getByRole('textbox', { name: /email/i });
    await user.type(emailInput, wrongEmail);
    const submitBtn = screen.getByRole('button', { name: /login:SIGN_IN/i, hidden: true });
    await user.click(submitBtn);

    await waitFor(() => expect(screen.queryByText('notifications:SIGNING_USER_MSG')).toBeInTheDocument(), { timeout: 1000 });
    act(() => {
      jest.advanceTimersByTime(7000);
    });
    expect(screen.queryByText('notifications:SIGNING_USER_MSG')).not.toBeVisible();

What you did:

I have a functionality where I have used notistick using snackbar and I am building a logic screen which only takes an email id and when the user clicks on a 'Sign In' button then the snackbar in displayed with the message 'notifications:SIGNING_USER_MSG' and when the login fails then I am displaying another snackbar, this specific snackbar auto closes after few seconds.

What happened:

I am able to access the snackbar but when I forward the timer and then expect the snackbar to have closed but it is still open, when I test the UI in google chrome then the snackbar auto closes after some seconds.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions