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

Unable to assert change to UI with testing library when a signal triggers the change #270

Open
nerdo opened this issue Nov 9, 2022 · 1 comment

Comments

@nerdo
Copy link

nerdo commented Nov 9, 2022

I ran into what appears to be a bug when using testing library and a simple signal.

Here's a stackblitz setup illustrating the issue: https://stackblitz.com/edit/vitejs-vite-adbvfx?file=src%2FApp.tsx,src%2FApp.test.tsx&terminal=dev

Each button simply triggers a function that sets a string. One does it using useState, and the other does it with a signal. When each respective value is set, it is displayed in a <div></div>.

There are tests inApp.test.tsx is where the issue lies. The test that tests clicking the button that changes the value with useState passes, while the one changing the value in a similar way with a signal fails.

To run the tests in the stackblitz, open the terminal and run vitest.

@mfal
Copy link

mfal commented Mar 21, 2024

You can workaround this issue by testing your expectations inside the waitFor function.

import React from "react";
import { expect, test } from "vitest";
import { render, waitFor } from "@testing-library/react";

test("Renders as expected", async () => {
  render(
    <ComponentUsingSignals />,
  );

  await waitFor(() => {
    // expectations
  });
});

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