How to use Jest to test file download?
I would mock out FileSaver
with a spy:
import FileSaver from 'file-saver';
jest.mock('file-saver', ()=>({saveAs: jest.fn()}))
As you cant compare Blobs I would mock this as well:
global.Blob = function (content, options){return ({content, options})}
now you can run your test and use expect like this
createDownload('content', 'filename', 'extension')
expect(FileSaver.saveAs).toHaveBeenCalledWith(
{content:'content', options: { type: 'application/octet-stream' }},
'filename.extension'
)