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

[StorageFactory] Unable to use Object.keys|entries|values(sessionStorage) after #1385 #1418

Closed
motss opened this issue Apr 26, 2024 · 0 comments · Fixed by #1423
Closed

[StorageFactory] Unable to use Object.keys|entries|values(sessionStorage) after #1385 #1418

motss opened this issue Apr 26, 2024 · 0 comments · Fixed by #1423
Labels
bug Something isn't working

Comments

@motss
Copy link
Contributor

motss commented Apr 26, 2024

Describe the bug
We can actually get all the keys of a Storage using Object.<keys|entries|values>() (Also see here). After #1385, it no longer works and we will seethe following error:

TypeError: 'getOwnPropertyDescriptor' on proxy: trap reported non-configurability for property '<key>' which is either non-existent or configurable in the proxy target

To Reproduce
Simple go to https://stackblitz.com/edit/vitest-dev-vitest-9lccsx and you will see the error in the terminal.

Also a simple code snippet to reproduce the error:

import { expect, it } from 'vitest';

it('Object.keys on window.sessionStorage', () => {
  window.sessionStorage.setItem('a', '1');

  expect(Object.keys(window.sessionStorage)).toEqual(['a']); // TypeError
  expect(Object.values(window.sessionStorage)).toEqual(['1']); // TypeError
  expect(Object.entries(window.sessionStorage)).toEqual([['a','1']]); // TypeError
});

Expected behavior
Object.keys(widow.sessionStorage) should return a list of keys in the sessionStorage

Screenshots

 FAIL  test/basic.test.ts > Object.keys on window.sessionStorage
TypeError: 'getOwnPropertyDescriptor' on proxy: trap reported non-configurability for property 'a' which is either non-existent or configurable in the proxy target
 ❯ eval test/basic.test.ts:5:39
      4|   window.sessionStorage.setItem('a', '1');
      5| 
      6|   expect(Object.keys(window.sessionStorage)).toEqual(['a']);
       |                                      ^
      7| });
      8| 

Device:

  • OS: Windows
  • Browser: Chrome
  • Version 125

Additional context
happy-dom version: 14.7.1

@motss motss added the bug Something isn't working label Apr 26, 2024
@motss motss changed the title [StorageFactory] Unable to use Object.keys(sessionStorage) after #1385 [StorageFactory] Unable to use Object.keys|entries|values(sessionStorage) after #1385 Apr 26, 2024
motss added a commit to motss/happy-dom that referenced this issue May 1, 2024
Signed-off-by: Rong Sen Ng (motss) <wes.ngrongsen@gmail.com>
motss added a commit to motss/happy-dom that referenced this issue May 1, 2024
Signed-off-by: Rong Sen Ng (motss) <wes.ngrongsen@gmail.com>
motss added a commit to motss/happy-dom that referenced this issue May 1, 2024
Signed-off-by: Rong Sen Ng (motss) <wes.ngrongsen@gmail.com>
capricorn86 added a commit that referenced this issue May 6, 2024
fix: [#1418] Fix Object.{entries,key,values} on Storage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant