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

fix: [#1418] Fix Object.{entries,key,values} on Storage #1423

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/happy-dom/src/storage/StorageFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ export default class StorageFactory {
) {
return;
}

return {
value: storage[PropertySymbol.data][key],
writable: true,
enumerable: true,
configurable: false
configurable: true
};
}
});
Expand Down
45 changes: 45 additions & 0 deletions packages/happy-dom/test/storage/Storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,51 @@ describe('Storage', () => {
});
});

describe('Object.keys()', () => {
it(`Returns an array of storage's own enumerable string-keyed property names.`, () => {
storage.setItem('key1', 'value1');
storage.setItem('key2', 'value2');

expect(storage.length).toBe(2);
expect(storage.getItem('key1')).toBe('value1');
expect(storage.getItem('key2')).toBe('value2');
expect(storage['key1']).toBe('value1');
expect(storage['key2']).toBe('value2');
expect(Object.keys(storage)).toEqual(['key1', 'key2']);
});
});

describe('Object.values()', () => {
it(`Returns an array of storage's own enumerable string-keyed property values.`, () => {
storage.setItem('key1', 'value1');
storage.setItem('key2', 'value2');

expect(storage.length).toBe(2);
expect(storage.getItem('key1')).toBe('value1');
expect(storage.getItem('key2')).toBe('value2');
expect(storage['key1']).toBe('value1');
expect(storage['key2']).toBe('value2');
expect(Object.values(storage)).toEqual(['value1', 'value2']);
});
});

describe('Object.entries()', () => {
it(`Returns an array of storage's own enumerable string-keyed property key-value pairs.`, () => {
storage.setItem('key1', 'value1');
storage.setItem('key2', 'value2');

expect(storage.length).toBe(2);
expect(storage.getItem('key1')).toBe('value1');
expect(storage.getItem('key2')).toBe('value2');
expect(storage['key1']).toBe('value1');
expect(storage['key2']).toBe('value2');
expect(Object.entries(storage)).toEqual([
['key1', 'value1'],
['key2', 'value2']
]);
});
});

describe('vi.spyOn()', () => {
it('Should spy on a method.', () => {
const spy = vi.spyOn(storage, 'getItem');
Expand Down
Loading