Open sstur opened 1 year ago
Not sure if this is a good way but I was able to mock Bun.file
with:
it('should return the contents of the file as a string', async () => {
const fileContents = 'This is the file contents.';
const path = '/path/to/file.txt';
const bunFileSpy = spyOn(Bun, 'file').mockImplementationOnce(
mock((_: string) => {
return {
text: () => Promise.resolve(fileContents),
};
}) as Mock<AnyFunction>
);
expect(await getArticleFileString(path)).toEqual(fileContents);
expect(bunFileSpy.mock.calls[0]).toEqual([path]);
});
What version of Bun is running?
0.7.3
What platform is your computer?
Darwin 22.2.0 arm64 arm
What steps can reproduce the bug?
Runtime error:
What is the expected behavior?
spyOn(...).mockImplementation()
should work onBun.file
as it would with other objects.What do you see instead?
Additional information
Currently there appears to be no way to mock
Bun.file()
. I mentioned this in Discord and opening this issue was suggested.