Skip to content

Commit

Permalink
return promise
Browse files Browse the repository at this point in the history
  • Loading branch information
roger authored and ShallmentMo committed Nov 14, 2017
1 parent e26650c commit 818ec3a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
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

0 comments on commit 818ec3a

Please sign in to comment.