One
Two
' + }} + debug={false} + renderers={{ div: DivRenderer }} + contentWidth={100} + /> + ); + expect(capturedKeys.length).toBeGreaterThanOrEqual(2); + expect(new Set(capturedKeys).size).toBe(capturedKeys.length); + }); + it('should generate unique keys for elements with the same tag and same nodeIndex in different subtrees', () => { + const capturedKeys: string[] = []; + const renderChild = jest.fn(({ key }) => { + capturedKeys.push(key); + return null; + }); + const DivRenderer: CustomTextualRenderer = jest.fn(function DivRenderer({ + TDefaultRenderer, + ...props + }) { + return ( +Nested One
Nested Two
One
Two
' + }} + debug={false} + renderers={{ div: DivRenderer }} + contentWidth={100} + /> + ); + // The key encodes the full ancestor path:at index 0 inside
differs only in its own nodeIndex (1 instead of 0)
+ expect(capturedKeys[1]).toBe(
+ 'tnode_childTnode--p-1-div-0-body-0-html-0'
+ );
+ });
+ it('should generate keys with the tnode_childTnode- prefix', () => {
+ const capturedKeys: string[] = [];
+ const renderChild = jest.fn(({ key }) => {
+ capturedKeys.push(key);
+ return null;
+ });
+ const DivRenderer: CustomTextualRenderer = jest.fn(function DivRenderer({
+ TDefaultRenderer,
+ ...props
+ }) {
+ return (
+ One Two