diff options
| author | Matt Mayer <[email protected]> | 2023-05-28 02:43:50 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-27 21:43:50 +0200 |
| commit | a5e73f8a11baeefcf03f344cb5e4dde096a0b364 (patch) | |
| tree | 94db06056940eacbe76186c6a8d3c43d3c72972b /test | |
| parent | 012ba2c80924b7bb1b241f170bae9dad25dacc2e (diff) | |
| download | faker-a5e73f8a11baeefcf03f344cb5e4dde096a0b364.tar.xz faker-a5e73f8a11baeefcf03f344cb5e4dde096a0b364.zip | |
fix(git): limit need for Intl to specific method (#2172)
Diffstat (limited to 'test')
| -rw-r--r-- | test/git.spec.ts | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/test/git.spec.ts b/test/git.spec.ts index 4000e71d..5926a0b7 100644 --- a/test/git.spec.ts +++ b/test/git.spec.ts @@ -1,6 +1,6 @@ import validator from 'validator'; import { describe, expect, it } from 'vitest'; -import { faker } from '../src'; +import { faker, FakerError } from '../src'; import { seededTests } from './support/seededRuns'; import { times } from './support/times'; @@ -114,6 +114,22 @@ describe('git', () => { expect(commitEntry).not.contains('\r\n'); }); + + it('should throw if Intl is unavailable', () => { + const backup = globalThis.Intl.DateTimeFormat; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (globalThis as any).Intl.DateTimeFormat = undefined; + + expect(() => { + faker.git.commitEntry(); + }).toThrow( + new FakerError( + 'This method requires an environment which supports Intl.NumberFormat and Intl.DateTimeFormat' + ) + ); + + globalThis.Intl.DateTimeFormat = backup; + }); }); describe('commitMessage', () => { @@ -138,6 +154,22 @@ describe('git', () => { const parts = commitDate.split(' '); expect(parts.length).toBe(6); }); + + it('should throw if Intl is unavailable', () => { + const backup = globalThis.Intl.DateTimeFormat; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (globalThis as any).Intl.DateTimeFormat = undefined; + + expect(() => { + faker.git.commitDate(); + }).toThrow( + new FakerError( + 'This method requires an environment which supports Intl.NumberFormat and Intl.DateTimeFormat' + ) + ); + + globalThis.Intl.DateTimeFormat = backup; + }); }); describe('commitSha', () => { |
