Skip to content

Commit

Permalink
✅ add getContainerXPath test
Browse files Browse the repository at this point in the history
  • Loading branch information
liaohainan committed Jun 6, 2022
1 parent ad5d85d commit 571ded6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
genAppInstanceIdByName,
getDefaultTplWrapper,
getWrapperId,
getContainerXPath,
getXPathForElement,
nextTask,
sleep,
Expand Down Expand Up @@ -100,6 +101,40 @@ test('Deferred should worked [2]', async () => {
expect(err).toBeInstanceOf(Error);
});

test('should getContainerXPath work well', () => {
const article = document.createElement('article');
article.innerHTML = `
<div>
<div></div>
<div id="testNode"></div>
<div></div>
</div>
`;

document.body.appendChild(article);
// const testNode = document.querySelector('#testNode');
const xpath = getContainerXPath('#testNode');
expect(xpath).toEqual(
// eslint-disable-next-line max-len
`/*[name()='HTML']/*[name()='BODY'][1]/*[name()='ARTICLE'][1]/*[name()='DIV'][1]/*[name()='DIV'][2]`,
);
const testNode2 = document.createElement('div');
testNode2.innerHTML = `
<div id="testNode2"></div>
`;

document.body.appendChild(testNode2);
const xpath1 = getContainerXPath(testNode2);

expect(xpath1).toEqual(
// eslint-disable-next-line max-len
`/*[name()='HTML']/*[name()='BODY'][1]/*[name()='DIV'][1]`,
);

const xpath2 = getContainerXPath(undefined);
expect(xpath2).toBeUndefined();
});

test('should getXPathForElement work well', () => {
const article = document.createElement('article');
article.innerHTML = `
Expand Down

0 comments on commit 571ded6

Please sign in to comment.