Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement API to simulate errors in fakeIndexedDB #106

Open
bartblast opened this issue Oct 10, 2024 · 0 comments
Open

Implement API to simulate errors in fakeIndexedDB #106

bartblast opened this issue Oct 10, 2024 · 0 comments

Comments

@bartblast
Copy link

Since fakeIndexedDB is used primarily for testing, I propose implementing an API to simulate errors. Due to the asynchronous nature of IndexedDB, most of the code contains error handlers which currently can't be tested.

For example, with this code:

const request = indexedDB.open("my_db", 1);

request.onerror = (event) => {
    throw new MyError("Failed to open database");
};

request.onsuccess = (event) => console.log("All is good!");

It's not possible to test error conditions. The open() function may fail due to many reasons, e.g.:

  • Storage limits
  • Insufficient permissions
  • Database version mismatch
  • Concurrent operations
  • Cross-origin issues

At the moment, the tests are only able to cover success cases.

Proposed Solution

One possible solution is to set this at the request class level, e.g.:

FDBOpenDBRequest.simulateError(event);

This would allow developers to simulate various error conditions and thoroughly test their error handling code.

@bartblast bartblast changed the title Implement API to Simulate Errors in fakeIndexedDB Implement API to simulate errors in fakeIndexedDB Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant