Skip to content

Commit

Permalink
Returning meaningful error on missing worksheet (#231)
Browse files Browse the repository at this point in the history
* Returning meaningful error on missing worksheet
  • Loading branch information
edmondop authored Nov 11, 2023
1 parent 6be12e3 commit b3befc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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.');
});
});

0 comments on commit b3befc9

Please sign in to comment.