Skip to content

Commit

Permalink
test: add tests for definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Jun 16, 2024
1 parent 74e944a commit 082a882
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
13 changes: 12 additions & 1 deletion test/modules/date.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { FakerError, faker, fakerAZ } from '../../src';
import { FakerError, allLocales, faker, fakerAZ } from '../../src';
import { seededTests } from '../support/seeded-runs';
import { times } from './../support/times';

Expand Down Expand Up @@ -665,6 +665,17 @@ describe('date', () => {
}
);

describe('definitions', () => {
describe('timeZone', () => {
// date.timezone data should only be available in the base locale
it.each(
Object.entries(allLocales).filter(([locale]) => locale !== 'base')
)('should not have any timezones in %s', (_, data) => {
expect(data.date?.time_zone).toBeUndefined();
});
});
});

describe('refDateSource', () => {
afterEach(() => {
faker.setDefaultRefDate();
Expand Down
35 changes: 34 additions & 1 deletion test/modules/location.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { describe, expect, it } from 'vitest';
import { FakerError, faker, fakerEN_CA, fakerEN_US } from '../../src';
import {
FakerError,
allLocales,
faker,
fakerEN_CA,
fakerEN_US,
} from '../../src';
import { seededTests } from '../support/seeded-runs';
import { times } from './../support/times';

Expand Down Expand Up @@ -390,6 +396,33 @@ describe('location', () => {
}
);
});

describe('timeZone', () => {
it('should return a random timezone', () => {
const actual = faker.location.timeZone();
expect(faker.definitions.location.time_zone).toContain(actual);
});
});
}
);
});

describe('definitions', () => {
describe('timeZone', () => {
it.each(Object.entries(allLocales))(
'locale data for %s should be a subset of the base locale',
(locale, data) => {
if (locale === 'base') {
expect(data.location?.time_zone).toEqual(
allLocales.base.date?.time_zone
);
} else if (data.location?.time_zone != null) {
// expected and actual are flipped here
expect(allLocales.base.date?.time_zone).toEqual(
expect.arrayContaining(data.location?.time_zone)
);
}
}
);
});
});

0 comments on commit 082a882

Please sign in to comment.