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

API to simulate the "close" event #50

Open
nolanlawson opened this issue Jun 27, 2020 · 1 comment
Open

API to simulate the "close" event #50

nolanlawson opened this issue Jun 27, 2020 · 1 comment

Comments

@nolanlawson
Copy link
Contributor

The "close" event on an IDBDatabase only fires when the database closes for an abnormal reason, as described in the spec. (An abnormal reason would be something like the user clearing their browser data while the IDB connection is open.)

For unit testing, it would be neat if fakeIndexedDB had an API for simulating this abnormal close event. Presumably it would just be a matter of running db.close() plus firing an event. (I would do this in userland, but it seems that fakeIndexedDB throws an error if you try to call db.dispatchEvent(new CustomEvent('close')).

@bugeats
Copy link

bugeats commented Jun 27, 2022

According to the MDN spec, it also needs to support addEventListener like so:

db.addEventListener("close", () => {
  console.log("Database connection closed");
});

And yeah @nolanlawson I ran into this when trying to do the perfectly reasonable task of writing tests to handle the DB closing when asking for a new transaction.

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

2 participants