schlechtenburg/packages/rich-text/lib/test/join.test.ts

46 lines
1 KiB
TypeScript
Raw Normal View History

2024-10-08 07:15:26 +00:00
import deepFreeze from 'deep-freeze';
import { describe, expect, it } from 'vitest'
import { join } from '../join';
import { getSparseArrayLength } from './helpers';
describe( 'join', () => {
const em = { type: 'em' };
const separators = [
' ',
{
formats: [ , ],
replacements: [ , ],
text: ' ',
},
];
separators.forEach( ( separator ) => {
it( 'should join records with string separator', () => {
const one = {
formats: [ , , [ em ] ],
replacements: [ , , , ],
text: 'one',
};
const two = {
formats: [ [ em ], , , ],
replacements: [ , , , ],
text: 'two',
};
const three = {
formats: [ , , [ em ], , [ em ], , , ],
replacements: [ , , , , , , , ],
text: 'one two',
};
const result = join(
[ deepFreeze( one ), deepFreeze( two ) ],
separator
);
expect( result ).not.toBe( one );
expect( result ).not.toBe( two );
expect( result ).toEqual( three );
expect( getSparseArrayLength( result.formats ) ).toBe( 2 );
} );
} );
} );