import PDFDocument from '../../lib/document'; import PDFTable from '../../lib/table'; import { deepMerge } from '../../lib/table/utils'; describe('table', () => { test('created', () => { const document = new PDFDocument(); expect(document.table()).toBeInstanceOf(PDFTable); expect(document.table({ data: [] })).toBe(document); }); test('row', () => { const document = new PDFDocument(); const table = document.table(); table.row(['A', 'B', 'C']); expect(table._columnWidths.length).toBe(3); }); }); describe('utils', () => { describe('deepMerge', () => { test.each([ [{ a: 'hello' }, { b: 'world' }, { a: 'hello', b: 'world' }], [{ a: 'hello' }, { a: 'world' }, { a: 'world' }], [{}, { a: 'hello' }, { a: 'hello' }], [{ a: 'hello' }, undefined, { a: 'hello' }], [undefined, null, undefined], [1, 2, 1], [1, {}, 1], [{ a: 'hello' }, { a: {} }, { a: 'hello' }], [{ a: { b: 'hello' } }, { a: { b: 'world' } }, { a: { b: 'world' } }], ])('%o -> %o', function () { const opts = Array.from(arguments); const expected = opts.splice(-1, 1)[0]; expect(deepMerge(...opts)).toEqual(expected); }); }); });