Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning meaningful error on missing worksheet #231

Merged
merged 3 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.');
});
});
Loading