axios-mock-adapter: How to mock a binary response

412 views Asked by At

Quite simular to that question I'd like to mock a PNG-Response with axios-mock-adapter.

What I tried yet:

import axios from 'axios'
import MockAdapter from 'axios-mock-adapter'
const fs = require('fs')
new MockAdapter(axios).onGet('dynamic.png').reply(200, fs.readFileSync(__dirname + '/mock.png'))

And another try:

// [...]
const bitmap = fs.readFileSync(__dirname + '/mock.png')
new MockAdapter(axios).onGet('dynamic.png').reply(200, new Buffer(bitmap).toString('base64'))

Any solution out there?

0

There are 0 answers