Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update test for nodeBelongs #1345

Merged
merged 2 commits into from
Jul 20, 2023
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
17 changes: 12 additions & 5 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,12 +37,13 @@ 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>
</div>
<div data-awsui-referrer-id="portal">
<div id="node"></div>
</div>
<div data-awsui-referrer-id="node"></div>
`;
expect(nodeBelongs(div.querySelector('#container1'), div.querySelector('#node') as Node)).toBe(true);
});
Expand Down
Loading