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

Property localStorage is not defined in Vitest using happy-dom@14.1.1 #1339

Closed
ottomated opened this issue Mar 20, 2024 · 5 comments · Fixed by #1340
Closed

Property localStorage is not defined in Vitest using happy-dom@14.1.1 #1339

ottomated opened this issue Mar 20, 2024 · 5 comments · Fixed by #1340
Assignees
Labels
bug Something isn't working high priority

Comments

@ottomated
Copy link

ottomated commented Mar 20, 2024

Describe the bug
Prior to 14.1.1, global uses of localStorage would work as expected. They no longer do.

To Reproduce
See codesandbox repro

Expected behavior
Global uses of window globals should work as expected.

Device:
All

@ottomated ottomated added the bug Something isn't working label Mar 20, 2024
@capricorn86 capricorn86 self-assigned this Mar 20, 2024
@capricorn86
Copy link
Owner

Thank you for reporting @ottomated! 🙂

I'm trying to reproduce the problem, but it seems like it is working in my environment.

I can't access the codesandbox. Is it possible for you to change permission?

@capricorn86
Copy link
Owner

It seems like it is working here:
https://stackblitz.com/edit/stackblitz-starters-ghue6z?file=index.js

@ottomated
Copy link
Author

Updated permissions

@capricorn86 capricorn86 changed the title localStorage is not defined on 14.1.1 Property localStorage is not defined in Vitest using happy-dom@14.1.1 Mar 20, 2024
capricorn86 added a commit that referenced this issue Mar 20, 2024
capricorn86 added a commit that referenced this issue Mar 20, 2024
…fined-on-1411

fix: [#1339] Fixes problem with properties defined as getters not bei…
@capricorn86
Copy link
Owner

capricorn86 commented Mar 20, 2024

@ottomated thank you for updating permissions.

There is a fix in now that solves the problem:
https://github.com/capricorn86/happy-dom/releases/tag/v14.1.2

I described the problem and solution in the release notes:

  • Fixes problem with properties defined as getters and setters not being registered globally by Vitest
    • The problem occurred as Vitest is using Object.getOwnPropertyDescriptors(window) to read which properties to register globally, but getters and setters are defined on the prototype
    • To solve the problem, GlobalWindow now defines the properties on the instance when it is constructed

@ottomated
Copy link
Author

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants