I want to test my application with Jest and Enzyme. I'm getting error:
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "[object Object]".] {
code: 'ERR_UNHANDLED_REJECTION'
}
It is caused by:
async function checkGet() {
const fetchedDB = await db.persons.toArray();
if (fetchedDB.length > 0) {
setPeople(fetchedDB);
return;
} else {
getPeople();
}
}
I tried to change it like that:
async function checkGet() {
const fetchedDB = await db.persons.toArray();
fetchedDB.catch((e) => {
console.log(e);
});
if (fetchedDB.length > 0) {
setPeople(fetchedDB);
return;
} else {
getPeople();
}
}
And like that:
async function checkGet() {
const fetchedDB = await db.persons.toArray().catch((e) => {
console.log(e);
});
if (fetchedDB.length > 0) {
setPeople(fetchedDB);
return;
} else {
getPeople();
}
}
But even after adding this, error still exists. I'm using React 17. Is it some sort of bug?