schlechtenburg/packages/rich-text/lib/test/concat.test.ts
2024-10-08 09:15:26 +02:00

33 lines
782 B
TypeScript

import deepFreeze from 'deep-freeze';
import { describe, expect, it } from 'vitest'
import { concat } from '../concat';
import { getSparseArrayLength } from './helpers';
describe( 'concat', () => {
const em = { type: 'em' };
it( 'should merge records', () => {
const one = {
formats: [ , , [ em ] ],
replacements: [ , , , ],
text: 'one',
};
const two = {
formats: [ [ em ], , , ],
replacements: [ , , , ],
text: 'two',
};
const three = {
formats: [ , , [ em ], [ em ], , , ],
replacements: [ , , , , , , ],
text: 'onetwo',
};
const merged = concat( deepFreeze( one ), deepFreeze( two ) );
expect( merged ).not.toBe( one );
expect( merged ).toEqual( three );
expect( getSparseArrayLength( merged.formats ) ).toBe( 2 );
} );
} );