Skip to content

Commit

Permalink
fix: add support for equals on locale proxies (#2092)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Apr 25, 2023
1 parent 698fd7d commit 4d0458c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/locale-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export function createLocaleProxy(locale: LocaleDefinition): LocaleProxy {
target: LocaleDefinition,
categoryName: keyof LocaleDefinition
): LocaleDefinition[keyof LocaleDefinition] {
if (typeof categoryName === 'symbol' || categoryName === 'nodeType') {
return target[categoryName];
}

if (categoryName in proxies) {
return proxies[categoryName];
}
Expand Down Expand Up @@ -69,7 +73,9 @@ function createCategoryProxy<
entryName: keyof CategoryData
): CategoryData[keyof CategoryData] {
const value = target[entryName];
if (value === null) {
if (typeof entryName === 'symbol' || entryName === 'nodeType') {
return value;
} else if (value === null) {
throw new FakerError(
`The locale data for '${categoryName}.${entryName.toString()}' aren't applicable to this locale.
If you think this is a bug, please report it at: https://github.com/faker-js/faker`
Expand Down
10 changes: 10 additions & 0 deletions test/locale-proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ describe('LocaleProxy', () => {
const locale = createLocaleProxy(en);
const enAirline = en.airline ?? { never: 'missing' };

describe('locale', () => {
it('should be possible to use equals on locale', () => {
expect(locale).toEqual(createLocaleProxy(en));
});

it('should be possible to use not equals on locale', () => {
expect(locale).not.toEqual(createLocaleProxy({}));
});
});

describe('category', () => {
it('should be possible to check for a missing category', () => {
expect('category' in locale).toBe(true);
Expand Down

0 comments on commit 4d0458c

Please sign in to comment.