Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
connorlanigan committed Jul 19, 2023
1 parent 685bedc commit 24b0039
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/internal/utils/__tests__/node-belongs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
import { nodeBelongs } from '../../../../lib/components/internal/utils/node-belongs';

describe('nodeBelongs', () => {
let div: HTMLDivElement;

beforeEach(() => {
div = document.createElement('div');
document.documentElement.appendChild(div);
});

afterEach(() => document.documentElement.removeChild(div));

test('returns "true", when the node and the container are the same element', () => {
const div = document.createElement('div');
div.innerHTML = `
<div id="container1"></div>
`;
expect(nodeBelongs(div.querySelector('#container1'), div.querySelector('#container1') as Node)).toBe(true);
});

test('returns "true", when the node is descendant from the container', () => {
const div = document.createElement('div');
div.innerHTML = `
<div id="container1">
<div id="node"></div>
Expand All @@ -22,7 +29,6 @@ describe('nodeBelongs', () => {
});

test('returns "false", when the node is not a child of the container', () => {
const div = document.createElement('div');
div.innerHTML = `
<div id="container1"></div>
<div id="node"></div>
Expand All @@ -31,7 +37,6 @@ describe('nodeBelongs', () => {
});

test('returns "true" when node belongs to a portal issued from within the container', () => {
const div = document.createElement('div');
div.innerHTML = `
<div id="container1">
<div id="portal"></div>
Expand All @@ -40,12 +45,6 @@ describe('nodeBelongs', () => {
<div id="node"></div>
</div>
`;
document.documentElement.appendChild(div);

try {
expect(nodeBelongs(div.querySelector('#container1'), div.querySelector('#node') as Node)).toBe(true);
} finally {
document.documentElement.removeChild(div);
}
expect(nodeBelongs(div.querySelector('#container1'), div.querySelector('#node') as Node)).toBe(true);
});
});

0 comments on commit 24b0039

Please sign in to comment.