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

How to mock a binary file? #37

Open
Mese1953 opened this issue Dec 17, 2024 · 1 comment
Open

How to mock a binary file? #37

Mese1953 opened this issue Dec 17, 2024 · 1 comment

Comments

@Mese1953
Copy link

I need to mock a fetch call, which returns a pdf.

Not sure who to do that. I've already tried some stuff like:

fetchMocker.mockResponseOnce(await readFile(path));
@dirkluijk
Copy link
Collaborator

dirkluijk commented Dec 17, 2024

I haven't tried this yet, but I think it should be something like:

import { readFile } from 'node:fs/promises';

const buffer = await readFile("path/to/file");

fetchMocker. mockResponseOnce(new Response(new Blob([buffer])));

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