Skip to content

Commit

Permalink
Merge pull request #629 from ro0gr/drop-$.text
Browse files Browse the repository at this point in the history
replace usages of `$.text(` with local implementation
  • Loading branch information
ro0gr committed Oct 15, 2023
2 parents 5014626 + 90d3f84 commit dd7220f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions addon/src/-private/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ export function isVisible(element) {
element.getClientRects().length
);
}

export function text(element) {
return element.textContent;
}

export function containsText(element, searchText) {
return text(element).indexOf(searchText) > -1;
}
8 changes: 4 additions & 4 deletions addon/src/properties/contains.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from '../-private/jquery';
import { containsText } from '../-private/element';
import { findOne } from '../-private/finders';
import { getter } from '../macros/index';

Expand Down Expand Up @@ -69,9 +69,9 @@ export function contains(selector, userOptions = {}) {
...userOptions,
};

return (
$(findOne(this, selector, options)).text().indexOf(textToSearch) > -1
);
const element = findOne(this, selector, options);

return containsText(element, textToSearch);
};
});
}
4 changes: 2 additions & 2 deletions addon/src/properties/text.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { $ } from '../-private/jquery';
import { findOne } from '../-private/finders';
import { getter } from '../macros/index';
import { text as textContent } from '../-private/element';

function identity(v) {
return v;
Expand Down Expand Up @@ -93,7 +93,7 @@ export function text(selector, userOptions = {}) {
};

let f = options.normalize === false ? identity : normalizeText;
return f($(findOne(this, selector, options)).text());
return f(textContent(findOne(this, selector, options)));
});
}

Expand Down

0 comments on commit dd7220f

Please # to comment.