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

Trying to mock a xlsx file for unit testing with Karma #118

Closed
JimtotheB opened this issue Sep 24, 2014 · 2 comments
Closed

Trying to mock a xlsx file for unit testing with Karma #118

JimtotheB opened this issue Sep 24, 2014 · 2 comments

Comments

@JimtotheB
Copy link

I'm trying to unit test an Angular.js controller that takes an array of files gotten from a drag and drop interface. I need to load a file from the server add it to my mock array then pass it to my parse function.

I'm using the example xhr loader to convert the file into a binary string, and this is the output I get trying to pass the the converted result directly to js-xlsx.

Error: End of data reached (data length = 211771, asked index = 273138). Corrupted zip ?

I have also seen this one.

Uncaught TypeError: Failed to construct 'Blob': 
The 1st argument is neither an array, nor does it have indexed properties.

And this one.

Uncaught TypeError: Failed to construct 'Blob': 
The 1st argument is neither an array, nor does it have indexed properties.

Somehow I need to load this file from the server and mock it to look like a file so my actual parse function can deal with it in the same way as if it was part of an array of dropped files. Any help with this would be greatly appreciated.

@SheetJSDev
Copy link
Contributor

@PaperElectron Admittedly I am not too familiar with Angular. Do you have sample code to reproduce the issue?

@JimtotheB
Copy link
Author

@SheetJSDev It turns out that this has nothing to do with this library or jszip. Karma, the test runner for Angular, is incapable of serving arbitrary binary files.

At the present time Karma serves binary files "wrong" unless the file extension matches a predefined list of binary formats. .xlsx and .xls aren't on this list. So if you are trying to server yourself a file to use as a mock user provided file js-xlsx will complain about it being corrupt. You can temporarily fix this by changing the file extension to .tar

You can see a bit more of the discussion here #1070

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants