Reputation: 1800
I have created a React App using Create React App, it uses IndexedDB.
When I try to run a test I'm getting this error:
[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 "ReferenceError: indexedDB is not defined".] {
code: 'ERR_UNHANDLED_REJECTION'
}
I understand that the testing suit is run in a headless browser that doesn't have IndexedDB.
How can I handle this case?
Upvotes: 3
Views: 4598
Reputation: 99
Actually, Jest is used to simulate the DOM in memory, not in an actual headless browser. For that reason, you have to mock that kind of APIs in order to make your tests pass.
I found an article that explains how to mock indexedDB in Jest
Upvotes: 1