Skip to content

Commit

Permalink
chore: Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Nov 11, 2024
1 parent a6322dc commit ffe7391
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/js-draw/src/testing/findNodeWithText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ interface Options {
}

/** Returns the first node or element with `textContent` matching `expectedText`. */
const findNodeWithText = (expectedText: string, parent: Node, options: Options): Node | null => {
const findNodeWithText = (
expectedText: string,
parent: Node,
options: Options = {},
): Node | null => {
const { tag } = options;

if (parent.textContent === expectedText) {
const matchesTag = parent instanceof Element && (!tag || tag.toUpperCase() === parent.tagName);
const matchesTag = (() => {
// No tag check necessary?
if (!tag) return true;
return parent instanceof Element && tag.toUpperCase() === parent.tagName;
})();

if (matchesTag) {
return parent;
Expand Down

0 comments on commit ffe7391

Please sign in to comment.