I’m unable to get a working unit test that calls IPFS.create()
. There has to be something obvious that I’m not aware of, but for the life of me I cannot find it.
// the unit tests
test('Test IPFS create method', async () => {
// expect.assertions(1);
const mockCreateIpfs = jest.fn(async () => await createIpfs());
await mockCreateIpfs();
expect(mockCreateIpfs).toHaveReturned();
});
test("Read the latest", async () => {
const mockGetLatest = jest.fn(async () => await getLatest());
await mockGetLatest();
expect(mockGetLatest).toHaveReturned();
});
// the functions
export async function createIpfs(props = {}) {
const memo = String(Object.entries(props)) || 'createIpfs';
if (memo in ipfsCreateMemo === false) {
console.log(Object.keys(IPFS)); // This verifies that IPFS is imported correctly
// The error always happens next
ipfsCreateMemo[memo] = await IPFS.create();
}
// never gets to this point
return ipfsCreateMemo[memo];
}
export async function getLatest() {
const ipfs = await createIpfs();
return ipfs.refs.local();
}
The first error is digest should be a Uint8Array
. If I test anything that calls IPFS.create
after that I will get LockExistsError: Lock already being held for file: /home/jhale/.jsipfs/repo.lock
.
How can I get this unit test to pass using IPFS.create
?