(node: Nullable<Text | ChildNode>, expectation: RegExp | string)
| 81 | node instanceof Text || ([...node.childNodes].every(childNode => childNode instanceof Text)); |
| 82 | |
| 83 | export const isTextNodeContaining = (node: Nullable<Text | ChildNode>, expectation: RegExp | string): boolean => { |
| 84 | // Make sure only text is being considered, not links, icons, etc |
| 85 | if (!node || !isTextNode(node)) { |
| 86 | console.warn('Expected Text node', node); |
| 87 | throw new TypeError(`Expected Text node, received ${String(node?.nodeName)}`); |
| 88 | } |
| 89 | |
| 90 | // The string/regex may expect spaces, like for `conventional-commits` |
| 91 | return matchString(expectation, node.textContent) || matchString(expectation, node.textContent.trim()); |
| 92 | }; |
| 93 | |
| 94 | export const assertNodeContent = <N extends Text | ChildNode>(node: Nullable<N>, expectation: RegExp | string): N => { |
| 95 | if (isTextNodeContaining(node, expectation)) { |
no test coverage detected