fakeIndexedDB icon indicating copy to clipboard operation
fakeIndexedDB copied to clipboard

FakeDOMStringList should not support array methods

Open shadow-light opened this issue 2 years ago • 4 comments

FakeDOMStringList seems to be extending array, but a number of array methods aren't available. Such that tests can pass and then result in failure in production.

I had a migration that executed transaction.objectStoreNames.includes('...') and didn't cause any issues, but then failed in production as should have been transaction.objectStoreNames.contains('...'). Didn't pick up on it with types due to a bug in idb

shadow-light avatar Sep 18 '21 17:09 shadow-light

This is a good point.

I think FakeDOMStringList does need to subclass/extend the built-in Array, because otherwise I don't know how you'd get various proper behaviors like destructuring. Please correct me if I'm wrong.

But it should either delete the Array-specific methods from the class or if that's not possible manually override them to throw errors. I think that should be possible, at least.

I was planning on doing a new release soon, I will try to include this.

dumbmatter avatar Sep 18 '21 18:09 dumbmatter

That sounds good, thanks for looking into it

shadow-light avatar Sep 19 '21 03:09 shadow-light

Turns out the solution I came up with in 7879a2459cc287d46076ec124a635c004ed55413 causes some problems when used with Dexie. I'm not sure why. But I guess it'll be safer to not do this, unless someone can help me figure out a better way.

dumbmatter avatar Jul 02 '22 18:07 dumbmatter

[].slice.call(arrayLike) is the problem, that is supposed to turn a DOMStringList into an array, but was not actually restoring the deleted methods.

dumbmatter avatar Jul 03 '22 01:07 dumbmatter