pdfkit/tests/unit/table.spec.js
chronospatian f3c1776850
Fix table with null text (#1609)
* Handle null values in table text

* Add test case for null value in table text

* Update CHANGELOG.md
2025-04-17 06:18:58 -03:00

38 lines
1.2 KiB
JavaScript

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);
});
});
});