Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/__tests__/__snapshots__/test-utils-wrappers.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ findCodeView(selector?: string): CodeViewWrapper | null;
* @returns {Array<CodeViewWrapper>}
*/
findAllCodeViews(selector?: string): Array<CodeViewWrapper>;

/**
* Returns the wrapper of the closest parent CodeView for the current element,
* or the element itself if it is an instance of CodeView.
* If no CodeView is found, returns \`null\`.
*
* @returns {CodeViewWrapper | null}
*/
findClosestCodeView(): CodeViewWrapper | null;
}
}

Expand All @@ -54,6 +63,11 @@ ElementWrapper.prototype.findAllCodeViews = function(selector) {
return this.findAllComponents(CodeViewWrapper, selector);
};

ElementWrapper.prototype.findClosestCodeView = function() {
// casting to 'any' is needed to avoid this issue with generics
// https://github.com/microsoft/TypeScript/issues/29132
return (this as any).findClosestComponent(CodeViewWrapper);
};

export default function wrapper(root: Element = document.body) {
if (document && document.body && !document.body.contains(root)) {
Expand Down
Loading