Skip to content

Commit

Permalink
test for appending inline elementNodes to ListNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Shopiley committed Nov 13, 2024
1 parent 23f4a7e commit 17b4078
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/lexical-list/src/__tests__/unit/LexicalListNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
*/
import {$isLinkNode, LinkNode} from '@lexical/link';
import {ParagraphNode, TextNode} from 'lexical';
import {initializeUnitTest} from 'lexical/src/__tests__/utils';

Expand Down Expand Up @@ -260,6 +261,31 @@ describe('LexicalListNode tests', () => {
});
});

test('ListNode.append() should wrap an InlineNode in a ListItemNode without converting it to TextNode', async () => {
const {editor} = testEnv;

await editor.update(() => {
const listNode = new ListNode('bullet', 1);
const linkNode = new LinkNode('https://lexical.dev/');

listNode.append(linkNode);

const firstChild = listNode.getFirstChild();
expect($isListItemNode(firstChild)).toBe(true);

if ($isListItemNode(firstChild)) {
const wrappedNode = firstChild?.getFirstChild();
expect($isLinkNode(wrappedNode)).toBe(true);

expect((wrappedNode as LinkNode).getURL()).toBe(
'https://lexical.dev/',
);
} else {
throw new Error('First child is not a ListItemNode');
}
});
});

test('$createListNode()', async () => {
const {editor} = testEnv;

Expand Down

0 comments on commit 17b4078

Please sign in to comment.