question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mock arraybuffer response (file download)

See original GitHub issue

I have an axios request that looks like:

    const res = await axios({
      method: 'get',
      url: `/reports/${report.id}`,
      responseType: 'arraybuffer',
    })
    const blob = new Blob([res.data], { type: 'text/csv' })
    let link = document.createElement('a')
    link.href = window.URL.createObjectURL(blob)
    link.download = report.name
    link.click()

How do I write a mock for it? This may be just a documentation issue…

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:7
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nitishsinghal29commented, Apr 10, 2020

I also have the same question

0reactions
spanwaircommented, Dec 16, 2021

I guess this can be simple done as:

mockAxios
      .onPost('url')
      .reply(200, Buffer.from('abc'));
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to mock axios zip download call, using ... - Stack Overflow
I am trying to unit test a method which calls this method and got stuck around mocking the zip download call. The code...
Read more >
Binary response type - Recipes - Mock Service Worker Docs
Here is an example of a mocked response that sends a local image: ... 6 // Convert "base64" image to "ArrayBuffer".
Read more >
Response.arrayBuffer() - Web APIs - MDN Web Docs
The arrayBuffer() method of the Response interface takes a Response stream ... Note that before playing full audio file will be downloaded.
Read more >
ArrayBuffer, binary arrays - The Modern JavaScript Tutorial
ArrayBuffer, binary arrays. In web-development we meet binary data mostly while dealing with files (create, upload, download).
Read more >
Angular Testing Snippets: the new HttpClient - Medium
Faking HTTP traffic and verifying for expected requests and responses. ... file upload component showing a progress indicator — when we fake out...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found