Skip to content

Commit

Permalink
Add support to text nodes - see #11
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodp committed Oct 5, 2024
1 parent a1b0f4e commit 11232b3
Show file tree
Hide file tree
Showing 4 changed files with 5,399 additions and 4,240 deletions.
19 changes: 19 additions & 0 deletions __tests__/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,23 @@ describe( 'getXPath', () => {
expect( rB ).toEqual( '/html/body/div/span[2]/button' );
} );

it( 'element with a single text node', () => {
const div = document.createElement( 'div' );
const text = document.createTextNode( 'Hello' );
div.appendChild( text );
document.body.appendChild( div );
const r = getXPath( text );
expect( r ).toEqual( '/html/body/div/text()[1]' );
} );

it( 'element with two text nodes', () => {
const div = document.createElement( 'div' );
const text1 = document.createTextNode( 'Hello' );
const text2 = document.createTextNode( 'World' );
div.append( text1, text2 );
document.body.appendChild( div );
const r = getXPath( text2 );
expect( r ).toEqual( '/html/body/div/text()[2]' );
} );

} );
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
"build": "microbundle --name=getXPath",
"check": "tsc __tests__/test.spec.ts --noEmit",
"test": "jest",
"all": "pnpm run check && pnpm run test && pnpm run build",
"all": "pnpm run test && pnpm run build",
"preversion": "pnpm run all",
"postversion": "git push && git push --tags"
},
"devDependencies": {
"@types/jest": "^25.2.3",
"@types/jsdom": "^21.1.7",
"del-cli": "^3.0.1",
"jest": "^26.6.3",
"jsdom": "^16.7.0",
Expand Down
Loading

0 comments on commit 11232b3

Please sign in to comment.