Skip to content

Commit 4d0458c

Browse files
authored
fix: add support for equals on locale proxies (#2092)
1 parent 698fd7d commit 4d0458c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/locale-proxy.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export function createLocaleProxy(locale: LocaleDefinition): LocaleProxy {
3131
target: LocaleDefinition,
3232
categoryName: keyof LocaleDefinition
3333
): LocaleDefinition[keyof LocaleDefinition] {
34+
if (typeof categoryName === 'symbol' || categoryName === 'nodeType') {
35+
return target[categoryName];
36+
}
37+
3438
if (categoryName in proxies) {
3539
return proxies[categoryName];
3640
}
@@ -69,7 +73,9 @@ function createCategoryProxy<
6973
entryName: keyof CategoryData
7074
): CategoryData[keyof CategoryData] {
7175
const value = target[entryName];
72-
if (value === null) {
76+
if (typeof entryName === 'symbol' || entryName === 'nodeType') {
77+
return value;
78+
} else if (value === null) {
7379
throw new FakerError(
7480
`The locale data for '${categoryName}.${entryName.toString()}' aren't applicable to this locale.
7581
If you think this is a bug, please report it at: https://github.com/faker-js/faker`

test/locale-proxy.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ describe('LocaleProxy', () => {
77
const locale = createLocaleProxy(en);
88
const enAirline = en.airline ?? { never: 'missing' };
99

10+
describe('locale', () => {
11+
it('should be possible to use equals on locale', () => {
12+
expect(locale).toEqual(createLocaleProxy(en));
13+
});
14+
15+
it('should be possible to use not equals on locale', () => {
16+
expect(locale).not.toEqual(createLocaleProxy({}));
17+
});
18+
});
19+
1020
describe('category', () => {
1121
it('should be possible to check for a missing category', () => {
1222
expect('category' in locale).toBe(true);

0 commit comments

Comments
 (0)