-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
A value which is actually Date, but instanceOf Date equals false when use with jest+jsdom. #98
Comments
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 think 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. ❤️ |
Fix issue #98: workaround to check date object
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 in
valueToKey.ts
will return false, step into else andthrow new DataError()
fakeIndexedDB/src/lib/valueToKey.ts
Line 11 in a1c1488
My 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.
The text was updated successfully, but these errors were encountered: