Skip to content

Conversation

@rchavan10
Copy link
Collaborator

@rchavan10 rchavan10 commented Dec 3, 2025

This PR closes #1960

@rchavan10 rchavan10 marked this pull request as ready for review December 3, 2025 16:00
@nx-cloud
Copy link

nx-cloud bot commented Dec 3, 2025

View your CI Pipeline Execution ↗ for commit 80fd336

Command Status Duration Result
nx affected --targets=lint,test,compodoc --conf... ✅ Succeeded 2m 25s View ↗
nx affected --target=build,build-webcomponent,b... ✅ Succeeded 42s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-19 20:49:41 UTC

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

🚀 Preview Deploy Report

✅ Successfully deployed preview here

@rchavan10 rchavan10 requested a review from axdanbol December 4, 2025 19:52
@rchavan10 rchavan10 linked an issue Dec 4, 2025 that may be closed by this pull request
8 tasks
@rchavan10 rchavan10 self-assigned this Dec 5, 2025
Copy link
Contributor

@axdanbol axdanbol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to use https://testing-library.com/ to interact with components and elements in the tests instead of relying on fixture and other brittle solutions

@rchavan10 rchavan10 requested a review from axdanbol December 18, 2025 19:37
async function setup(data?: string) {
const user = userEvent.setup();
const result = await render(MarkdownComponent, {
providers: [provideMarkdown(), provideHttpClient(), provideAnalytics()],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add provideHttpClientTesting()

});

it('should call logEvent when anchor is clicked', async () => {
const { container, fixture, user, logEventSpy } = await setup('# Test\n[Link](https://example.com)');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use container or fixture. Use screen.getBy*, etc.

const anchor = container.querySelector('a[href="https://example.com"]') as HTMLAnchorElement;
expect(anchor).toBeTruthy();

component.attachEventListeners();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should automatically be called when the markdown is rendered. Have you verified that the event doesn't fire as it should?

expect(logEventSpy).toHaveBeenCalled();
});

it('should push listeners when attaching event listeners', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this test


it('should call unlisten functions when clearing event listeners', async () => {
const { container, fixture } = await setup('# Test\n[Link](https://example.com)');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grab a reference to the anchor then call rerender and test that clicking the old anchor element doesn't generate a logEvent

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

Successfully merging this pull request may close these issues.

@hra-ui/design-system: Increase test coverage

3 participants