diff options
| author | Shinigami <[email protected]> | 2023-10-17 22:03:32 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-17 20:03:32 +0000 |
| commit | c0330442be99988db57e9dad12ebdcd3b3a92213 (patch) | |
| tree | 49a7814ef2a3b3a05b147e8be790c4712ef414e8 /test/modules | |
| parent | f3de0f61dc517a4548150fd40498a9df6d4b97e6 (diff) | |
| download | faker-c0330442be99988db57e9dad12ebdcd3b3a92213.tar.xz faker-c0330442be99988db57e9dad12ebdcd3b3a92213.zip | |
infra(unicorn): prefer-spread (#2421)
Co-authored-by: ST-DDT <[email protected]>
Diffstat (limited to 'test/modules')
| -rw-r--r-- | test/modules/datatype.spec.ts | 24 | ||||
| -rw-r--r-- | test/modules/helpers.spec.ts | 16 | ||||
| -rw-r--r-- | test/modules/number.spec.ts | 16 | ||||
| -rw-r--r-- | test/modules/random.spec.ts | 17 | ||||
| -rw-r--r-- | test/modules/string.spec.ts | 20 | ||||
| -rw-r--r-- | test/modules/system.spec.ts | 6 |
6 files changed, 49 insertions, 50 deletions
diff --git a/test/modules/datatype.spec.ts b/test/modules/datatype.spec.ts index e3e052ef..964636bc 100644 --- a/test/modules/datatype.spec.ts +++ b/test/modules/datatype.spec.ts @@ -164,8 +164,8 @@ describe('datatype', () => { }); it('provides numbers with a given precision of 0.5 steps', () => { - const results = Array.from( - new Set( + const results = [ + ...new Set( Array.from({ length: 50 }, () => faker.datatype.float({ min: 0, @@ -173,16 +173,16 @@ describe('datatype', () => { precision: 0.5, }) ) - ) - ).sort(); + ), + ].sort(); expect(results).toEqual([0, 0.5, 1, 1.5]); }); // TODO @Shinigami92 2022-11-24: https://github.com/faker-js/faker/issues/1595 it.todo('provides numbers with a given precision of 0.4 steps', () => { - const results = Array.from( - new Set( + const results = [ + ...new Set( Array.from({ length: 50 }, () => faker.datatype.float({ min: 0, @@ -190,8 +190,8 @@ describe('datatype', () => { precision: 0.4, }) ) - ) - ).sort(); + ), + ].sort(); expect(results).toEqual([0, 0.4, 0.8, 1.2, 1.6]); }); @@ -279,11 +279,11 @@ describe('datatype', () => { it('provides numbers with a given precision', () => { const options = { min: 0, max: 1.5, precision: 0.5 }; - const results = Array.from( - new Set( + const results = [ + ...new Set( Array.from({ length: 50 }, () => faker.datatype.float(options)) - ) - ).sort(); + ), + ].sort(); expect(results).toEqual([0, 0.5, 1, 1.5]); }); diff --git a/test/modules/helpers.spec.ts b/test/modules/helpers.spec.ts index be023b15..0564a794 100644 --- a/test/modules/helpers.spec.ts +++ b/test/modules/helpers.spec.ts @@ -71,7 +71,7 @@ describe('helpers', () => { }); t.describe('arrayElement', (t) => { - t.it('with array', 'Hello World!'.split('')); + t.it('with array', [...'Hello World!']); }); t.describe('enumValue', (t) => { @@ -120,26 +120,26 @@ describe('helpers', () => { }); t.describe('arrayElements', (t) => { - t.it('with array', 'Hello World!'.split('')) - .it('with array and count', 'Hello World!'.split(''), 3) - .it('with array and count range', 'Hello World!'.split(''), { + t.it('with array', [...'Hello World!']) + .it('with array and count', [...'Hello World!'], 3) + .it('with array and count range', [...'Hello World!'], { min: 1, max: 5, }); }); t.describe('shuffle', (t) => { - t.it('with array', 'Hello World!'.split('')) - .it('with array and inplace true', 'Hello World!'.split(''), { + t.it('with array', [...'Hello World!']) + .it('with array and inplace true', [...'Hello World!'], { inplace: true, }) - .it('with array and inplace false', 'Hello World!'.split(''), { + .it('with array and inplace false', [...'Hello World!'], { inplace: false, }); }); t.describe('uniqueArray', (t) => { - t.it('with array', 'Hello World!'.split(''), 3); + t.it('with array', [...'Hello World!'], 3); }); t.describe('maybe', (t) => { diff --git a/test/modules/number.spec.ts b/test/modules/number.spec.ts index 19bd8f39..79b14261 100644 --- a/test/modules/number.spec.ts +++ b/test/modules/number.spec.ts @@ -227,8 +227,8 @@ describe('number', () => { }); it('provides numbers with a given precision of 0.5 steps', () => { - const results = Array.from( - new Set( + const results = [ + ...new Set( Array.from({ length: 50 }, () => faker.number.float({ min: 0, @@ -236,15 +236,15 @@ describe('number', () => { precision: 0.5, }) ) - ) - ).sort(); + ), + ].sort(); expect(results).toEqual([0, 0.5, 1, 1.5]); }); it('provides numbers with a given precision of 0.4 steps', () => { - const results = Array.from( - new Set( + const results = [ + ...new Set( Array.from({ length: 50 }, () => faker.number.float({ min: 0, @@ -252,8 +252,8 @@ describe('number', () => { precision: 0.4, }) ) - ) - ).sort(); + ), + ].sort(); expect(results).toEqual([0, 0.4, 0.8, 1.2, 1.6]); }); diff --git a/test/modules/random.spec.ts b/test/modules/random.spec.ts index 21200c3a..80fa10aa 100644 --- a/test/modules/random.spec.ts +++ b/test/modules/random.spec.ts @@ -194,8 +194,9 @@ describe('random', () => { }); it('should throw if all possible characters being banned', () => { - const bannedChars = - 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); + const bannedChars = [ + ...'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + ]; expect(() => faker.random.alpha({ count: 5, @@ -256,7 +257,7 @@ describe('random', () => { ); it('should be able to ban all alphabetic characters', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split(''); + const bannedChars = [...'abcdefghijklmnopqrstuvwxyz']; const alphaText = faker.random.alphaNumeric(5, { bannedChars, }); @@ -280,7 +281,7 @@ describe('random', () => { }); it('should be able to ban all numeric characters', () => { - const bannedChars = '0123456789'.split(''); + const bannedChars = [...'0123456789']; const alphaText = faker.random.alphaNumeric(5, { bannedChars, }); @@ -314,7 +315,7 @@ describe('random', () => { }); it('should throw if all possible characters being banned', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'.split(''); + const bannedChars = [...'abcdefghijklmnopqrstuvwxyz0123456789']; expect(() => faker.random.alphaNumeric(5, { bannedChars, @@ -396,7 +397,7 @@ describe('random', () => { it('should allow leading zeros via option and all other digits banned', () => { const actual = faker.random.numeric(4, { allowLeadingZeros: true, - bannedDigits: '123456789'.split(''), + bannedDigits: [...'123456789'], }); expect(actual).toBe('0000'); @@ -415,7 +416,7 @@ describe('random', () => { expect(() => faker.random.numeric(4, { allowLeadingZeros: false, - bannedDigits: '123456789'.split(''), + bannedDigits: [...'123456789'], }) ).toThrow( new FakerError( @@ -439,7 +440,7 @@ describe('random', () => { it('should ban all digits passed via bannedDigits', () => { const actual = faker.random.numeric(1000, { - bannedDigits: 'c84U1'.split(''), + bannedDigits: [...'c84U1'], }); expect(actual).toHaveLength(1000); diff --git a/test/modules/string.spec.ts b/test/modules/string.spec.ts index 4b885a3a..9d2debba 100644 --- a/test/modules/string.spec.ts +++ b/test/modules/string.spec.ts @@ -9,14 +9,14 @@ describe('string', () => { seededTests(faker, 'string', (t) => { t.describe('fromCharacters', (t) => { t.it('with string characters', 'foobar') - .it('with string[] characters', 'foobar'.split('')) + .it('with string[] characters', [...'foobar']) .it('with string characters and length', 'foobar', 5) - .it('with string[] characters and length', 'foobar'.split(''), 5) + .it('with string[] characters and length', [...'foobar'], 5) .it('with string characters and length range', 'foobar', { min: 10, max: 20, }) - .it('with string[] characters and length range', 'foobar'.split(''), { + .it('with string[] characters and length range', [...'foobar'], { min: 10, max: 20, }); @@ -283,7 +283,7 @@ describe('string', () => { }); it('should throw if all possible characters being excluded (string[])', () => { - const exclude = 'abcdefghijklmnopqrstuvwxyz'.split(''); + const exclude = [...'abcdefghijklmnopqrstuvwxyz']; expect(() => faker.string.alpha({ length: 5, @@ -357,7 +357,7 @@ describe('string', () => { }); it('should be able to ban all alphabetic characters', () => { - const exclude = 'abcdefghijklmnopqrstuvwxyz'.split(''); + const exclude = [...'abcdefghijklmnopqrstuvwxyz']; const alphaText = faker.string.alphanumeric({ length: 5, casing: 'lower', @@ -385,7 +385,7 @@ describe('string', () => { }); it('should be able to ban all numeric characters', () => { - const exclude = '0123456789'.split(''); + const exclude = [...'0123456789']; const alphaText = faker.string.alphanumeric({ length: 5, exclude, @@ -437,7 +437,7 @@ describe('string', () => { }); it('should throw if all possible characters being excluded (string[])', () => { - const exclude = 'abcdefghijklmnopqrstuvwxyz0123456789'.split(''); + const exclude = [...'abcdefghijklmnopqrstuvwxyz0123456789']; expect(() => faker.string.alphanumeric({ length: 5, @@ -645,7 +645,7 @@ describe('string', () => { const actual = faker.string.numeric({ length: 4, allowLeadingZeros: true, - exclude: '123456789'.split(''), + exclude: [...'123456789'], }); expect(actual).toBe('0000'); @@ -666,7 +666,7 @@ describe('string', () => { faker.string.numeric({ length: 4, allowLeadingZeros: false, - exclude: '123456789'.split(''), + exclude: [...'123456789'], }) ).toThrow( new FakerError( @@ -692,7 +692,7 @@ describe('string', () => { it('should ban all digits passed via exclude', () => { const actual = faker.string.numeric({ length: 1000, - exclude: 'c84U1'.split(''), + exclude: [...'c84U1'], }); expect(actual).toHaveLength(1000); diff --git a/test/modules/system.spec.ts b/test/modules/system.spec.ts index 1ce31c3c..b325468d 100644 --- a/test/modules/system.spec.ts +++ b/test/modules/system.spec.ts @@ -405,13 +405,11 @@ describe('system', () => { ); it('should be able to return non-standard cron expressions', () => { - const validResults = [...'0123456789'.split(''), '*', '@']; + const validResults = new Set('0123456789*@'); expect( faker.system.cron({ includeNonStandard: true })[0], 'generated cron, string should contain standard or non-standard cron labels' - ).toSatisfy( - (value) => !!validResults.find((result) => value === result) - ); + ).toSatisfy((value: string) => validResults.has(value)); }); }); } |
