Reputation: 217
Using Mirage i need to mock my GET request which returns data in the form of binary string (the format is gzip). It is my first time using mirage and i don't know if i'm mocking a binary response, should I return a valid value? here is how i mocked it for now.
this.get('/myproxy/api/v1/network/download', function (db, request) {
let responseBlob = new window.Blob(['To be replaced with my actual binary data'], {type: 'application/octet-stream'})
return new Response(
200,
{'content-disposition': "attachment; filename=network.myextension; filename*=UTF-8''network.myextension"},
responseBlob
)
})
Here is my scenario: Upon receiving response from backend, i just convert the repose to blob and download it as a file. If i should create a valid binary data when i'm mocking data, how can i do it using mirage? should i store it as a file somewhere and use it as the mocked response? I appreciate if someone can help me.
Upvotes: 14
Views: 1655
Reputation: 65183
I don't recommend mirage these days, and will recommend against folks using Mirage if they're looking to adopt something new.
MSW is a well-funded project, which works great with Ember, and has an example of using a binary response: https://mswjs.io/docs/recipes/binary-response-type
Upvotes: 0