happy-dom
happy-dom copied to clipboard
`Object.keys(localStorage)` returns ['_store'] not the keys stored
Describe the bug
Object.keys(localStorage)
returns ['_store'] not the keys stored
You have to do Object.keys(localStorage._store)
to get the keys.
This also happens with for-in loop.
Using "happy-dom": "^12.10.3"
To Reproduce Steps to reproduce the behavior:
- Set values on localStorage
- Run
Object.keys(localStorage)
- See incorrect result
Expected behavior Object.keys(localStorage) should return keys that were set.
Device:
- OS: macos m1 latest version
Workaround:
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
// access each key
}
I encountered the same situation as you, after emulating the storage of a value, I used Object.keys(window.localStorage)
to get an empty array.
Than you for reporting @knownasilya! and @XiaoDaiGua-Ray! :slightly_smiling_face:
A big thanks to @frankdiw for contributing with a fix :star2:
You can read more about the release here: https://github.com/capricorn86/happy-dom/releases/tag/v14.3.1