Closed sjnho closed 3 months ago
I would think that if jsdom is overwriting the Date object, then the code inside fake-indexeddb should also have that Date object and it should work. But I guess that's not working right.
Can you give me a minimal reproduction to help make debugging easier?
@dumbmatter Sorry for my slow reply. I create a repo. https://github.com/sjnho/fakeindexeddb-jest-debug
I think Object.prototype.toString.call(input) === '[object Date]'
is probably a valid solution... https://stackoverflow.com/a/643827/786644 points out that there are other valid cases where instanceof
can fail. In theory someone could make some other object that returns "[object Date]" from toString, but that is probably less likely than using jsdom like you did.
If you want to send a PR feel free! If not just say so and I'll do it, it's only one line of code (and probably a comment explaining it and linking here) - I just want to give you the opportunity to take credit for it with a PR if you want :)
No problem, I will send a PR. ❤️
This is in v6.0.0 :)
I have a objectStore with index via a Date value.
Add some test data like
{data:"test",created:new Date()}
in jest test suite. But when I run as follow code.The cursor is always null. And I
console.log (index._rawIndex.records).
It is an empty array. After my investigation , the reason is jsdom override Date, so the date instance check invalueToKey.ts
will return false, step into else andthrow new DataError()
https://github.com/dumbmatter/fakeIndexedDB/blob/a1c148880d227fa218473efeac11d4e36dfa8b73/src/lib/valueToKey.ts#L11My workaround is override global.Date
How do you think about it ? Do we need fix it using like
Object.prototype.toString.call(input ) === '[object Date]'
Or keep the workaround.