Skip to content

Commit

Permalink
Returning meaningful error on missing worksheet
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondop committed Oct 3, 2023
1 parent 6be12e3 commit 46a4336
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
40 changes: 34 additions & 6 deletions packages/xlsx-import/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/xlsx-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"devDependencies": {
"@types/chai": "^4.2.14",
"@types/mocha": "^5.2.7",
"@types/node": "^20.8.2",
"chai": "^4.2.0",
"markdownlint-cli": "^0.31.0",
"mocha": "^9.2.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/xlsx-import/src/Importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export class Importer implements IImporter {
const { worksheet } = config;
const type = (config.type as ImportType) || IMPORT_TYPE_DEFAULT;
const ws = this.wb.getWorksheet(worksheet);

if (!ws) {
throw new Error(`Worksheet "${worksheet}" not found in workbook.`);
}
return getStrategyByType(type)(config, ws);
}

Expand Down
10 changes: 10 additions & 0 deletions packages/xlsx-import/tests/integration/vertical-lists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ describe('testing vertical list - on file "marsjanie-db"', () => {
],
rowOffset: 1,
},
not_existing_wroksheet: {
worksheet: 'dummy'
}
};

it('worksheet "szit1"', async () => {
Expand Down Expand Up @@ -180,4 +183,11 @@ describe('testing vertical list - on file "marsjanie-db"', () => {

chai.expect(result).eql(expected);
});

it(`should return a meaningful error when the worksheet is not found`, async() => {
const factory = new ImporterFactory();
const importer = await factory.from('tests/data/marsjanie-db.xlsx');
const result = () => importer.getAllItems(configs.not_existing_wroksheet);
chai.expect(result).to.throw('Worksheet "dummy" not found in workbook.');
});
});
3 changes: 2 additions & 1 deletion packages/xlsx-import/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"outDir": "./lib",
"strict": true,
"esModuleInterop": true,
"sourceMap": true
"sourceMap": true,
"lib": ["ES2015", "DOM", "ES2017", "ES2017.Object", "ESNext", "DOM.Iterable"]
},
"include": ["src"],
"exclude": [
Expand Down

0 comments on commit 46a4336

Please sign in to comment.