import 'expect-puppeteer'; import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport'; describe('convert() API', function() { describe('convert from HTML table', function() { beforeEach(() => { window.URL.createObjectURL = () => "blob:fake_URL"; document.body.innerHTML = ''; const element = document.createElement("div"); element.innerHTML = '
firstsecond
1234123.56
' + 'Link'; document.body.appendChild(element); }); test('should create a XLSX from HTML table by #id', function() { const options = { anchor: 'anchor', filename: 'data_from_table', format: 'xlsx' } as ConvertOptions; const sheets = [ { name: 'Sheet Name Here 1', from: { table: 'sometable' } } ] as SheetOptions[]; const workbook = ExcellentExport.convert(options, sheets); expect(workbook).not.toBeNull(); const anchor = document.getElementById('anchor') as HTMLAnchorElement; expect(anchor.href).not.toBeNull(); expect(anchor.href).toMatch(/blob:/); }); test('should create a XLSX from HTML table by DOM element', function() { const options = { anchor: document.getElementById('anchor'), filename: 'data_from_table', format: 'xlsx' } as ConvertOptions; const sheets = [ { name: 'Sheet Name Here 1', from: { table: document.getElementById('sometable') } } ] as SheetOptions[]; const workbook = ExcellentExport.convert(options, sheets); expect(workbook).not.toBeNull(); const anchor = document.getElementById('anchor') as HTMLAnchorElement; expect(anchor.href).not.toBeNull(); expect(anchor.href).toMatch(/blob:/); }); }); });