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

Array values should not turn into proxies #5

Merged
merged 3 commits into from
Sep 10, 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
2 changes: 2 additions & 0 deletions .yarn/versions/071e6ed7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
theme-party: patch
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { JestConfigWithTsJest } from 'ts-jest'
const jestConfig: JestConfigWithTsJest = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
testMatch: ['<rootDir>/src/**/*.test.ts?(x)'],
};

export default jestConfig;
27 changes: 27 additions & 0 deletions src/__tests__/ThemeParty.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assert, Equals } from 'tsafe';
import util from 'util';

import { ThemeParty } from '../ThemeParty';

Expand Down Expand Up @@ -161,3 +162,29 @@ test('getTheme with selector', () => {
lg: 16,
});
});

test('proxy values', () => {
const themeParty = new ThemeParty({
string: 'string',
number: 1,
boolean: true,
object: { key: 'value' },
array: [1, 2, 3],
function: () => ({ function: true }),
});

const theme = themeParty.getTheme();
expect(util.types.isProxy(theme)).toBe(true);
expect(theme.string).toBe('string');
expect(util.types.isProxy(theme.string)).toBe(false);
expect(theme.number).toBe(1);
expect(util.types.isProxy(theme.number)).toBe(false);
expect(theme.boolean).toBe(true);
expect(util.types.isProxy(theme.boolean)).toBe(false);
expect(theme.object).toEqual({ key: 'value' });
expect(util.types.isProxy(theme.object)).toBe(true);
expect(theme.array).toEqual([1, 2, 3]);
expect(util.types.isProxy(theme.array)).toBe(false);
expect(theme.function).toEqual({ function: true });
expect(util.types.isProxy(theme.function)).toBe(false);
})
2 changes: 1 addition & 1 deletion src/makeThemeProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function makeThemeProxy<T extends {}>(theme: ThemeConfig<T>): ThemeExtrac
return value(new Proxy(theme, handler));
}

if (typeof value === "object" && value !== null) {
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
return new Proxy(value, handler);
}

Expand Down
Loading