I am trying to test a service that uses expo-file-system. Specifically I just want to mock out FileSystem.cacheDirectory since that's the first instance of my code that uses FileSystem.
I tried __mocks__/expo-file-system.ts
export default {
cacheDirectory: jest.fn(() => "<cache>/"),
};
And
jest.mock("expo-file-system", () => {
return jest.fn().mockImplementation(() => {
return {
cacheDirectory: jest.fn(() => "<cache>/"),
};
});
});
My test I think looks simple enough
import * as FileSystem from "expo-file-system";
// This part I tried commenting out
jest.mock("expo-file-system", () => {
return jest.fn().mockImplementation(() => {
return {
cacheDirectory: jest.fn(() => "<cache>/"),
};
});
});
it("verify mock", () => {
expect(FileSystem.cacheDirectory).toBe("<cache>/");
});
But I always get FileSystem.cacheDirectory as undefined
I also have the jest-expo dependency and preset.
This is a simple scenario compared to Why doesn't expo-file-system work in Jest?