Skip to content

feat: findClosest* test utilities#115

Merged
jperals merged 9 commits intomainfrom
feat/find-closest
Mar 23, 2026
Merged

feat: findClosest* test utilities#115
jperals merged 9 commits intomainfrom
feat/find-closest

Conversation

@jperals
Copy link
Member

@jperals jperals commented Mar 16, 2026

Issue: D406188710

Consuming packages fail as expected because the generated test utils do not match their snapshots. We will have to merge this PR following the instructions in 2ksIAPIa8aCi and update the snapshots in each of these consuming packages after that.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jperals jperals force-pushed the feat/find-closest branch from dc092bc to b8bd469 Compare March 17, 2026 16:43
@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.03%. Comparing base (59ba705) to head (362fd07).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #115      +/-   ##
==========================================
+ Coverage   96.96%   97.03%   +0.06%     
==========================================
  Files           9        9              
  Lines         330      337       +7     
  Branches       72       73       +1     
==========================================
+ Hits          320      327       +7     
  Misses         10       10              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

if ('legacyRootSelector' in ComponentClass && ComponentClass.legacyRootSelector) {
componentRootSelector = `:is(.${ComponentClass.rootSelector}, .${ComponentClass.legacyRootSelector})`;
}
const componentRootSelector = getComponentRootSelector(ComponentClass);
Copy link
Member Author

Choose a reason for hiding this comment

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

Deduplicated this logic which exists for both dom and selectors

@jperals jperals changed the title feat: Provide closestX API for DOM test utils feat: findClosest* test utilities Mar 19, 2026
@jperals jperals marked this pull request as ready for review March 19, 2026 08:06
@jperals jperals requested a review from a team as a code owner March 19, 2026 08:07
@jperals jperals requested review from georgylobko and removed request for a team March 19, 2026 08:07
@jperals jperals requested a review from SpyZzey March 20, 2026 10:49

const nestedElements = document.createElement('div');
nestedElements.innerHTML = `
<div class="outer-component" data-id="outer">
Copy link
Member

Choose a reason for hiding this comment

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

Should we call this data-testid to follow most of our other tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

document.body.removeChild(nestedElements);
});

it('returns the closest parent matching the component type', () => {
Copy link
Member

Choose a reason for hiding this comment

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

This does not really check the "closest parent matching the component type", as we currently only have one InnerWrapper. Can we test that too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

const result = childWrapper.findClosestComponent(UnrelatedWrapper);
expect(result).toBeNull();
});
});
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest adding test coverage for sibling structures like:

<Component1>
  <Component2 />
</Component1>
<Component3>
  <Component4 />
</Component3>

When looking up the closest component for Component4 or Component3, the result should not match Component1 or Component2 as they're in a separate subtree

Copy link
Member Author

Choose a reason for hiding this comment

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

Added coverage for this in b0af06d.

Copy link
Member Author

Choose a reason for hiding this comment

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

And added a specific test for this in the latest commit

@jperals jperals force-pushed the feat/find-closest branch from 4998376 to b0af06d Compare March 23, 2026 09:59
georgylobko
georgylobko previously approved these changes Mar 23, 2026
@jperals jperals added this pull request to the merge queue Mar 23, 2026
Merged via the queue into main with commit 23ae428 Mar 23, 2026
39 of 43 checks passed
@jperals jperals deleted the feat/find-closest branch March 23, 2026 12:28
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.

3 participants