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

return promise #11

Merged
merged 1 commit into from
Nov 15, 2017
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
5 changes: 2 additions & 3 deletions __test__/zipcelx.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ console.error = jest.genMockFn();
describe('Zipcelx', () => {
const rowsXML = `<row r="1"><c r="A1" t="inlineStr"><is><t>Test</t></is></c><c r="B1"><v>1000</v></c></row>`;

it('Should console log error if validator fails', () => {
it('Should throw error if validator fails', () => {
let config = Object.assign({}, baseConfig, { sheet: { data: [{test: 'demo'}] } });
zipcelx(config);
expect(console.error).toBeCalled();
expect(() => zipcelx(config)).toThrow();
});

it('Should map row arrays to XML markup', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/zipcelx.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var generateXMLWorksheet = exports.generateXMLWorksheet = function generateXMLWo

exports.default = function (config) {
if (!(0, _validator2.default)(config)) {
return;
throw new Error('Validation failed.');
}

var zip = new _jszip2.default();
Expand All @@ -63,7 +63,7 @@ exports.default = function (config) {
var worksheet = generateXMLWorksheet(config.sheet.data);
xl.file('worksheets/sheet1.xml', worksheet);

zip.generateAsync({ type: 'blob' }).then(function (blob) {
return zip.generateAsync({ type: 'blob' }).then(function (blob) {
_fileSaver2.default.saveAs(blob, config.filename + '.xlsx');
});
};
4 changes: 2 additions & 2 deletions src/zipcelx.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const generateXMLWorksheet = (rows) => {

export default (config) => {
if (!validator(config)) {
return;
throw new Error('Validation failed.');
}

const zip = new JSZip();
Expand All @@ -30,7 +30,7 @@ export default (config) => {
const worksheet = generateXMLWorksheet(config.sheet.data);
xl.file('worksheets/sheet1.xml', worksheet);

zip.generateAsync({ type: 'blob' })
return zip.generateAsync({ type: 'blob' })
.then((blob) => {
FileSaver.saveAs(blob, `${config.filename}.xlsx`);
});
Expand Down