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

ExternalHyperlink button causes @testing-library/react getByRole('link') queries to hang with v11 of Canvas Kit #3032

Closed
ahayes91 opened this issue Nov 5, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@ahayes91
Copy link
Contributor

ahayes91 commented Nov 5, 2024

🐛 Bug Report

ExternalHyperlink button causes @testing-library/react getByRole('link') queries to hang with v11 of Canvas Kit

To Reproduce

The test for reference:

import { render, screen } from '@testing-library/react';
import { describe, test, expect } from 'vitest';
import { ExternalHyperlink } from '@workday/canvas-kit-react/button';

const TestComponent = () => <a href="https://www.google.com">Click me!</a>;
const TestCanvasComponent = () => (
  <ExternalHyperlink href="https://www.google.com">Click me!</ExternalHyperlink>
);

describe('Testing Canvas Kit and @testing-library/react:', () => {
  test('This hangs', async () => {
    render(<TestCanvasComponent />);
    expect(
      await screen.findByRole('link', {
        name: /Click me!/,
      })
    ).toBeDefined();
  });
  test('This passes', async () => {
    render(<TestComponent />);
    expect(
      await screen.findByRole('link', { name: 'Click me!' })
    ).toBeDefined();
  });
});

Expected Behavior

Both tests should pass

Actual Results

Test using Canvas Kit ExternalHyperlink button fails

Link to repl or repo (highly encouraged)

⬆️

Error Output

no error, the test just hangs

@ahayes91 ahayes91 added the bug Something isn't working label Nov 5, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in Canvas Kit Nov 5, 2024
@NicholasBoll
Copy link
Member

NicholasBoll commented Nov 5, 2024

When you say “hangs”, I think it is because you’re using findBy* rather than getBy*. get* queries are instant while find* queries retry until time out.

The ExternalLink has an external link image that has a label of “Opens in new window”. This adds to the label of the external link. For example:

<ExternalHyperlink href="https://google.com">Some Link</ExternalHyperlink>

This has the accessible name computed to:

Some Link Opens in new window

image

The external icon has this label for accessibility to inform screen reader users that the link opens in a new window. The icon is for visual users to know it opens in a new window.

@NicholasBoll
Copy link
Member

If you wish to not include the "Opens link in new window" in your name, you can use a regular expression instead:

    expect(
      await screen.findByRole('link', { name: /Click me!/ })
    ).toBeDefined();

@ahayes91
Copy link
Contributor Author

ahayes91 commented Nov 5, 2024

I did know about the extra label but I forgot! https://stackblitz.com/edit/canvas-kit-react-v11-starter-w7cqqu-9gfiwe?file=src%2FApp.test.tsx updated but it still never actually times out (from what I can tell!)

@ahayes91
Copy link
Contributor Author

ahayes91 commented Nov 5, 2024

https://stackblitz.com/edit/canvas-kit-react-v10-starter-pbwauw?file=src%2FApp.test.tsx is a Stackblitz with all the same tests / happy-dom / vitest config, and the tests pass

@ahayes91
Copy link
Contributor Author

ahayes91 commented Nov 5, 2024

@ahayes91
Copy link
Contributor Author

ahayes91 commented Nov 7, 2024

Nicholas spotted that the problem here is actually happy-dom - when we switch to jsdom, CK 11 works fine:

https://stackblitz.com/edit/canvas-kit-react-v11-starter-w7cqqu-5xmrfs?file=src%2FApp.test.tsx,vite.config.ts

I can raise something on the happy-dom repo for traceability (and in case we do really need happy-dom over jsdom in the future, it might crop up again).
Otherwise I've got two paths forward - switch to jsdom, or upgrade straight to CK v12, both of which are pretty reasonable!

Thanks for the investigation ❤️

@ahayes91
Copy link
Contributor Author

ahayes91 commented Nov 7, 2024

Closing this in favour of capricorn86/happy-dom#1593, workarounds listed above!

@ahayes91 ahayes91 closed this as completed Nov 7, 2024
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in Canvas Kit Nov 7, 2024
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
Status: ✅ Done
Development

No branches or pull requests

2 participants