-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
45 lines (43 loc) · 1.53 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const assert = require('assert');
const xlsx = require('xlsx');
const md2xlsx = require('../lib');
const table = require('../lib/table');
const sheetObj = require('./fixtures/hello.json');
describe('xlsx', () => {
describe('parser', () => {
it('write file', () => {
md2xlsx('./test/fixtures/hello.md');
const xlsxObj = xlsx.readFile('./hello.xlsx');
const sheet = xlsxObj.Sheets.Sheet1;
assert.deepStrictEqual(sheet, sheetObj);
});
it('workbook only', () => {
const workbook = md2xlsx('./test/fixtures/hello.md', { workbook: true });
const sheet = workbook.Sheets.Sheet1;
assert.deepStrictEqual(workbook.SheetNames, ['Sheet1']);
Object.keys(sheet).forEach(key => {
const value = sheet[key];
if (typeof value === 'string') {
assert.strictEqual(value, sheetObj[key]);
} else {
const { t, v } = sheetObj[key];
assert.deepStrictEqual(value, { t, v });
}
});
});
});
describe('invalid table', () => {
it('length < 3', () => {
assert.throws(table.toWorkbook.bind(null, 'm|n\n|-|'), Error, 'invalid table');
});
it('empty header', () => {
assert.throws(table.toWorkbook.bind(null, '\n|-|\nx|y'), Error, 'invalid table');
});
it('invalid header', () => {
assert.throws(table.toWorkbook.bind(null, 'm|n\n|-|\nx|y'), Error, 'invalid table');
});
it('invalid separator', () => {
assert.throws(table.toWorkbook.bind(null, 'm|n\n|-|\nx|y'), Error, 'invalid table');
});
});
});