aboutsummaryrefslogtreecommitdiff
path: root/test/modules
diff options
context:
space:
mode:
authorShinigami <[email protected]>2024-02-27 17:10:27 +0100
committerGitHub <[email protected]>2024-02-27 17:10:27 +0100
commit682a4276f13d7b8f48e1bd8aafcf011c7bd10390 (patch)
tree28af1816a09b165449adbc9eca9a415ff156077c /test/modules
parentc1caa900ceb12737a3aa45b7e4dd75797a11a889 (diff)
downloadfaker-682a4276f13d7b8f48e1bd8aafcf011c7bd10390.tar.xz
faker-682a4276f13d7b8f48e1bd8aafcf011c7bd10390.zip
refactor(datatype)!: remove v8 deprecated datatype methods (#2694)
Diffstat (limited to 'test/modules')
-rw-r--r--test/modules/__snapshots__/datatype.spec.ts.snap351
-rw-r--r--test/modules/__snapshots__/helpers.spec.ts.snap82
-rw-r--r--test/modules/datatype.spec.ts506
-rw-r--r--test/modules/helpers.spec.ts6
4 files changed, 45 insertions, 900 deletions
diff --git a/test/modules/__snapshots__/datatype.spec.ts.snap b/test/modules/__snapshots__/datatype.spec.ts.snap
index ba5c2ad1..9d6707ba 100644
--- a/test/modules/__snapshots__/datatype.spec.ts.snap
+++ b/test/modules/__snapshots__/datatype.spec.ts.snap
@@ -1,42 +1,5 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
-exports[`datatype > 42 > array > noArgs 1`] = `
-[
- "ky2eiXX/J/",
- 6503186795855872,
- 8453731307749376,
- "!1}2Z=YQ!I",
- "<QYF-%<{C6",
- ")jZ3DP|XL%",
- 5472277529362432,
- 1535944771502080,
- "'"yxzUlD="",
-]
-`;
-
-exports[`datatype > 42 > array > with length 1`] = `
-[
- "ky2eiXX/J/",
- 6503186795855872,
- 8453731307749376,
-]
-`;
-
-exports[`datatype > 42 > array > with length range 1`] = `
-[
- 8563273238577152,
- "eiXX/J/*&K",
- 3005779955154944,
- 1286829863075840,
-]
-`;
-
-exports[`datatype > 42 > bigInt > noArgs 1`] = `379177551410048n`;
-
-exports[`datatype > 42 > bigInt > with value 1`] = `37n`;
-
exports[`datatype > 42 > boolean > noArgs 1`] = `true`;
exports[`datatype > 42 > boolean > noArgs 2`] = `false`;
@@ -51,124 +14,6 @@ exports[`datatype > 42 > boolean > with probability 1`] = `true`;
exports[`datatype > 42 > boolean > with probability option 1`] = `false`;
-exports[`datatype > 42 > datetime > noArgs 1`] = `2031-03-14T21:33:22.114Z`;
-
-exports[`datatype > 42 > datetime > with given number 1`] = `1994-03-20T17:23:00.629Z`;
-
-exports[`datatype > 42 > datetime > with max 1`] = `1994-07-11T09:43:47.230Z`;
-
-exports[`datatype > 42 > datetime > with min 1`] = `1801-04-11T15:13:06.330Z`;
-
-exports[`datatype > 42 > datetime > with min and max 1`] = `1689-09-09T08:39:09.444Z`;
-
-exports[`datatype > 42 > float > noArgs 1`] = `37453.64`;
-
-exports[`datatype > 42 > float > repeated 1`] = `37453.64`;
-
-exports[`datatype > 42 > float > repeated 2`] = `79653.5`;
-
-exports[`datatype > 42 > float > repeated 3`] = `95070.48`;
-
-exports[`datatype > 42 > float > repeated 4`] = `18343.29`;
-
-exports[`datatype > 42 > float > repeated 5`] = `73198.66`;
-
-exports[`datatype > 42 > float > repeated 6`] = `77968.32`;
-
-exports[`datatype > 42 > float > with max 1`] = `25.84`;
-
-exports[`datatype > 42 > float > with min 1`] = `37411.64`;
-
-exports[`datatype > 42 > float > with min and max 1`] = `-0.43`;
-
-exports[`datatype > 42 > float > with min, max and precision 1`] = `-0.4261`;
-
-exports[`datatype > 42 > hexadecimal > noArgs 1`] = `"0x8"`;
-
-exports[`datatype > 42 > hexadecimal > with casing 1`] = `"0x8"`;
-
-exports[`datatype > 42 > hexadecimal > with length 1`] = `"0x8BE4ABdd39321aD7d3fe01FfCE404F4d6db0906bd8"`;
-
-exports[`datatype > 42 > hexadecimal > with length, prefix, and casing 1`] = `"0x8be4abdd39321ad7d3fe"`;
-
-exports[`datatype > 42 > hexadecimal > with prefix 1`] = `"0x8"`;
-
-exports[`datatype > 42 > json 1`] = `"{"foo":"ky2eiXX/J/","bar":"&[email protected]]\\"&","bike":6503186795855872,"a":8453731307749376,"b":"!1}2Z=YQ!I","name":"<QYF-%<{C6","prop":")jZ3DP|XL%"}"`;
-
-exports[`datatype > 42 > number > noArgs 1`] = `37454`;
-
-exports[`datatype > 42 > number > repeated 1`] = `2`;
-
-exports[`datatype > 42 > number > repeated 2`] = `5`;
-
-exports[`datatype > 42 > number > repeated 3`] = `6`;
-
-exports[`datatype > 42 > number > repeated 4`] = `1`;
-
-exports[`datatype > 42 > number > repeated 5`] = `5`;
-
-exports[`datatype > 42 > number > with max 1`] = `26`;
-
-exports[`datatype > 42 > number > with min 1`] = `37412`;
-
-exports[`datatype > 42 > number > with min and max 1`] = `-1`;
-
-exports[`datatype > 42 > number > with min, max and precision 1`] = `-0.43`;
-
-exports[`datatype > 42 > string > noArgs 1`] = `"Cky2eiXX/J"`;
-
-exports[`datatype > 42 > string > with length option 1`] = `"Cky2eiXX/J/*&[email protected]]"&"`;
-
-exports[`datatype > 42 > string > with number 1`] = `"Cky2eiXX/J/*&[email protected]]"&{dnx4!1}2Z=YQ!I#<QYF"`;
-
-exports[`datatype > 42 > uuid 1`] = `"5cf2bc99-2721-407d-8592-ba00fbdf302f"`;
-
-exports[`datatype > 42 > uuid 2`] = `"94980604-8962-404f-a537-1c9368f970d9"`;
-
-exports[`datatype > 42 > uuid 3`] = `"2710fff9-c640-413a-937a-197d02e642ac"`;
-
-exports[`datatype > 42 > uuid 4`] = `"6838920f-dc7f-46ee-a9be-519380f5d6b4"`;
-
-exports[`datatype > 42 > uuid 5`] = `"d95f4984-24c2-410f-86c6-3400d3bbbcc9"`;
-
-exports[`datatype > 1211 > array > noArgs 1`] = `
-[
- 4134441414819840,
- 7010029022478336,
- "-}$_/\`4hHA",
- "afl"h^]dnw",
- "<q|p|5KWu3",
- "CZ|Jh!E=x"",
- 3794869965291520,
- 1431627091673088,
- "V<1bEQuA|p",
- "DW9F=V1(U7",
-]
-`;
-
-exports[`datatype > 1211 > array > with length 1`] = `
-[
- 4134441414819840,
- 7010029022478336,
- "-}$_/\`4hHA",
- "afl"h^]dnw",
-]
-`;
-
-exports[`datatype > 1211 > array > with length range 1`] = `
-[
- "ti5-}$_/\`4",
- 3789861976801280,
- "0afl"h^]dn",
- 3918465303838720,
- "q|p|5KWu3/",
-]
-`;
-
-exports[`datatype > 1211 > bigInt > noArgs 1`] = `948721906162743n`;
-
-exports[`datatype > 1211 > bigInt > with value 1`] = `8n`;
-
exports[`datatype > 1211 > boolean > noArgs 1`] = `false`;
exports[`datatype > 1211 > boolean > noArgs 2`] = `true`;
@@ -183,122 +28,6 @@ exports[`datatype > 1211 > boolean > with probability 1`] = `false`;
exports[`datatype > 1211 > boolean > with probability option 1`] = `false`;
-exports[`datatype > 1211 > datetime > noArgs 1`] = `2092-02-20T03:42:04.341Z`;
-
-exports[`datatype > 1211 > datetime > with given number 1`] = `2000-06-14T02:54:42.082Z`;
-
-exports[`datatype > 1211 > datetime > with max 1`] = `2001-03-20T11:14:25.251Z`;
-
-exports[`datatype > 1211 > datetime > with min 1`] = `2065-11-10T19:27:20.915Z`;
-
-exports[`datatype > 1211 > datetime > with min and max 1`] = `1789-03-26T15:44:45.219Z`;
-
-exports[`datatype > 1211 > float > noArgs 1`] = `92851.09`;
-
-exports[`datatype > 1211 > float > repeated 1`] = `92851.09`;
-
-exports[`datatype > 1211 > float > repeated 2`] = `45901.06`;
-
-exports[`datatype > 1211 > float > repeated 3`] = `89346.28`;
-
-exports[`datatype > 1211 > float > repeated 4`] = `77826.18`;
-
-exports[`datatype > 1211 > float > repeated 5`] = `22556.85`;
-
-exports[`datatype > 1211 > float > repeated 6`] = `12988.8`;
-
-exports[`datatype > 1211 > float > with max 1`] = `64.07`;
-
-exports[`datatype > 1211 > float > with min 1`] = `92809.09`;
-
-exports[`datatype > 1211 > float > with min and max 1`] = `61.07`;
-
-exports[`datatype > 1211 > float > with min, max and precision 1`] = `61.0658`;
-
-exports[`datatype > 1211 > hexadecimal > noArgs 1`] = `"0xE"`;
-
-exports[`datatype > 1211 > hexadecimal > with casing 1`] = `"0xe"`;
-
-exports[`datatype > 1211 > hexadecimal > with length 1`] = `"0xEaDB42F0e3f4A973fAB0AeefCE96DFCF49cD438dF9"`;
-
-exports[`datatype > 1211 > hexadecimal > with length, prefix, and casing 1`] = `"0xeadb42f0e3f4a973fab0"`;
-
-exports[`datatype > 1211 > hexadecimal > with prefix 1`] = `"0xE"`;
-
-exports[`datatype > 1211 > json 1`] = `"{"foo":4134441414819840,"bar":7010029022478336,"bike":"-}$_/\`4hHA","a":"afl\\"h^]dnw","b":"<q|p|5KWu3","name":"CZ|Jh!E=x\\"","prop":3794869965291520}"`;
-
-exports[`datatype > 1211 > number > noArgs 1`] = `92852`;
-
-exports[`datatype > 1211 > number > repeated 1`] = `6`;
-
-exports[`datatype > 1211 > number > repeated 2`] = `3`;
-
-exports[`datatype > 1211 > number > repeated 3`] = `6`;
-
-exports[`datatype > 1211 > number > repeated 4`] = `5`;
-
-exports[`datatype > 1211 > number > repeated 5`] = `1`;
-
-exports[`datatype > 1211 > number > with max 1`] = `64`;
-
-exports[`datatype > 1211 > number > with min 1`] = `92810`;
-
-exports[`datatype > 1211 > number > with min and max 1`] = `61`;
-
-exports[`datatype > 1211 > number > with min, max and precision 1`] = `61.07`;
-
-exports[`datatype > 1211 > string > noArgs 1`] = `"wKti5-}$_/"`;
-
-exports[`datatype > 1211 > string > with length option 1`] = `"wKti5-}$_/\`4hHA0afl"h^"`;
-
-exports[`datatype > 1211 > string > with number 1`] = `"wKti5-}$_/\`4hHA0afl"h^]dnwI<q|p|5KWu3/CZ|J"`;
-
-exports[`datatype > 1211 > uuid 1`] = `"e7ec32f0-a2a3-4c65-b2bb-d0caabde64df"`;
-
-exports[`datatype > 1211 > uuid 2`] = `"f379e325-9f7c-4064-be08-6f23942b68e5"`;
-
-exports[`datatype > 1211 > uuid 3`] = `"d4694649-2183-4b32-90bd-7a336639d699"`;
-
-exports[`datatype > 1211 > uuid 4`] = `"10ab829b-742c-4a8b-a773-298d718d7706"`;
-
-exports[`datatype > 1211 > uuid 5`] = `"7b91ce88-effb-4d1d-b13b-bad759e00b86"`;
-
-exports[`datatype > 1337 > array > noArgs 1`] = `
-[
- "U/4:SK$>6Q",
- 2359372120326144,
- "{:e=+kD)[B",
- "e|/Jqjjj!B",
- "GDWQgC2M;q",
- 3648103756333056,
- "I1.Gm3tRwn",
- 1668592164667392,
- 8623125245722624,
- 3831794621218816,
-]
-`;
-
-exports[`datatype > 1337 > array > with length 1`] = `
-[
- "U/4:SK$>6Q",
- 2359372120326144,
- "{:e=+kD)[B",
- "e|/Jqjjj!B",
-]
-`;
-
-exports[`datatype > 1337 > array > with length range 1`] = `
-[
- 1429298200182784,
- ":SK$>6QX9@",
- 2436284417048576,
-]
-`;
-
-exports[`datatype > 1337 > bigInt > noArgs 1`] = `251225403255239n`;
-
-exports[`datatype > 1337 > bigInt > with value 1`] = `25n`;
-
exports[`datatype > 1337 > boolean > noArgs 1`] = `true`;
exports[`datatype > 1337 > boolean > noArgs 2`] = `false`;
@@ -312,83 +41,3 @@ exports[`datatype > 1337 > boolean > noArgs 5`] = `true`;
exports[`datatype > 1337 > boolean > with probability 1`] = `true`;
exports[`datatype > 1337 > boolean > with probability option 1`] = `false`;
-
-exports[`datatype > 1337 > datetime > noArgs 1`] = `2018-10-28T08:46:11.896Z`;
-
-exports[`datatype > 1337 > datetime > with given number 1`] = `1992-12-13T04:13:59.232Z`;
-
-exports[`datatype > 1337 > datetime > with max 1`] = `1993-03-02T00:10:04.335Z`;
-
-exports[`datatype > 1337 > datetime > with min 1`] = `1747-07-16T01:19:54.159Z`;
-
-exports[`datatype > 1337 > datetime > with min and max 1`] = `1669-06-22T01:21:21.236Z`;
-
-exports[`datatype > 1337 > float > noArgs 1`] = `26202.2`;
-
-exports[`datatype > 1337 > float > repeated 1`] = `26202.2`;
-
-exports[`datatype > 1337 > float > repeated 2`] = `56052.42`;
-
-exports[`datatype > 1337 > float > repeated 3`] = `15868.24`;
-
-exports[`datatype > 1337 > float > repeated 4`] = `21258.55`;
-
-exports[`datatype > 1337 > float > repeated 5`] = `27812.37`;
-
-exports[`datatype > 1337 > float > repeated 6`] = `54307.53`;
-
-exports[`datatype > 1337 > float > with max 1`] = `18.08`;
-
-exports[`datatype > 1337 > float > with min 1`] = `26160.2`;
-
-exports[`datatype > 1337 > float > with min and max 1`] = `-12.92`;
-
-exports[`datatype > 1337 > float > with min, max and precision 1`] = `-12.9153`;
-
-exports[`datatype > 1337 > hexadecimal > noArgs 1`] = `"0x5"`;
-
-exports[`datatype > 1337 > hexadecimal > with casing 1`] = `"0x5"`;
-
-exports[`datatype > 1337 > hexadecimal > with length 1`] = `"0x5c346ba075bd57F5A62B82d72AF39CBBB07a98cbA8"`;
-
-exports[`datatype > 1337 > hexadecimal > with length, prefix, and casing 1`] = `"0x5c346ba075bd57f5a62b"`;
-
-exports[`datatype > 1337 > hexadecimal > with prefix 1`] = `"0x5"`;
-
-exports[`datatype > 1337 > json 1`] = `"{"foo":"U/4:SK$>6Q","bar":2359372120326144,"bike":"{:e=+kD)[B","a":"e|/Jqjjj!B","b":"GDWQgC2M;q","name":3648103756333056,"prop":"I1.Gm3tRwn"}"`;
-
-exports[`datatype > 1337 > number > noArgs 1`] = `26202`;
-
-exports[`datatype > 1337 > number > repeated 1`] = `1`;
-
-exports[`datatype > 1337 > number > repeated 2`] = `3`;
-
-exports[`datatype > 1337 > number > repeated 3`] = `1`;
-
-exports[`datatype > 1337 > number > repeated 4`] = `1`;
-
-exports[`datatype > 1337 > number > repeated 5`] = `1`;
-
-exports[`datatype > 1337 > number > with max 1`] = `18`;
-
-exports[`datatype > 1337 > number > with min 1`] = `26160`;
-
-exports[`datatype > 1337 > number > with min and max 1`] = `-13`;
-
-exports[`datatype > 1337 > number > with min, max and precision 1`] = `-12.92`;
-
-exports[`datatype > 1337 > string > noArgs 1`] = `"9U/4:SK$>6"`;
-
-exports[`datatype > 1337 > string > with length option 1`] = `"9U/4:SK$>6QX9@{:e=+kD)"`;
-
-exports[`datatype > 1337 > string > with number 1`] = `"9U/4:SK$>6QX9@{:e=+kD)[B,e|/Jqjjj!BLGDWQgC"`;
-
-exports[`datatype > 1337 > uuid 1`] = `"48234870-5389-445f-b4b4-1c61a52bf27d"`;
-
-exports[`datatype > 1337 > uuid 2`] = `"cc057669-8c53-474d-ba67-7226d3e8ed92"`;
-
-exports[`datatype > 1337 > uuid 3`] = `"fe6d8b8b-0db9-4fa2-9726-5abc0a5d0ccf"`;
-
-exports[`datatype > 1337 > uuid 4`] = `"0b87afbd-8949-4dfb-84d0-419f4fe7458b"`;
-
-exports[`datatype > 1337 > uuid 5`] = `"0bcea83c-a7ea-428e-9c5d-bd448f2b777a"`;
diff --git a/test/modules/__snapshots__/helpers.spec.ts.snap b/test/modules/__snapshots__/helpers.spec.ts.snap
index 04b416a2..63c7513f 100644
--- a/test/modules/__snapshots__/helpers.spec.ts.snap
+++ b/test/modules/__snapshots__/helpers.spec.ts.snap
@@ -81,28 +81,28 @@ exports[`helpers > 42 > maybe > with value and probability 1`] = `undefined`;
exports[`helpers > 42 > multiple > with method and count 1`] = `
[
- 37454,
- 79654,
- 95071,
- 18343,
- 73199,
+ 3373557438480384,
+ 7174621373661184,
+ 8563273238577152,
+ 1652233682812928,
+ 6593215255805952,
]
`;
exports[`helpers > 42 > multiple > with method and count range 1`] = `
[
- 79654,
- 95071,
- 18343,
- 73199,
+ 7174621373661184,
+ 8563273238577152,
+ 1652233682812928,
+ 6593215255805952,
]
`;
exports[`helpers > 42 > multiple > with only method 1`] = `
[
- 37454,
- 79654,
- 95071,
+ 3373557438480384,
+ 7174621373661184,
+ 8563273238577152,
]
`;
@@ -307,34 +307,34 @@ exports[`helpers > 1211 > maybe > with value and probability 1`] = `undefined`;
exports[`helpers > 1211 > multiple > with method and count 1`] = `
[
- 92852,
- 45901,
- 89347,
- 77826,
- 22557,
+ 8363366036799488,
+ 4134441414819840,
+ 8047677172350976,
+ 7010029022478336,
+ 2031760839802880,
]
`;
exports[`helpers > 1211 > multiple > with method and count range 1`] = `
[
- 45901,
- 89347,
- 77826,
- 22557,
- 12988,
- 99725,
- 3842,
- 67199,
- 15897,
- 68481,
+ 4134441414819840,
+ 8047677172350976,
+ 7010029022478336,
+ 2031760839802880,
+ 1169939440336896,
+ 8982492805595136,
+ 346135076012032,
+ 6052754548064256,
+ 1431911878623232,
+ 6168278875504640,
]
`;
exports[`helpers > 1211 > multiple > with only method 1`] = `
[
- 92852,
- 45901,
- 89347,
+ 8363366036799488,
+ 4134441414819840,
+ 8047677172350976,
]
`;
@@ -528,27 +528,27 @@ exports[`helpers > 1337 > maybe > with value and probability 1`] = `undefined`;
exports[`helpers > 1337 > multiple > with method and count 1`] = `
[
- 26202,
- 56052,
- 15868,
- 21258,
- 27812,
+ 2360108468142080,
+ 5048803172286464,
+ 1429298200182784,
+ 1914819313664000,
+ 2505140957347840,
]
`;
exports[`helpers > 1337 > multiple > with method and count range 1`] = `
[
- 56052,
- 15868,
- 21258,
+ 5048803172286464,
+ 1429298200182784,
+ 1914819313664000,
]
`;
exports[`helpers > 1337 > multiple > with only method 1`] = `
[
- 26202,
- 56052,
- 15868,
+ 2360108468142080,
+ 5048803172286464,
+ 1429298200182784,
]
`;
diff --git a/test/modules/datatype.spec.ts b/test/modules/datatype.spec.ts
index ca6c3328..0dc59fe4 100644
--- a/test/modules/datatype.spec.ts
+++ b/test/modules/datatype.spec.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
-import { FakerError, faker } from '../../src';
+import { faker } from '../../src';
import { seededTests } from '../support/seeded-runs';
import { times } from './../support/times';
@@ -7,366 +7,16 @@ const NON_SEEDED_BASED_RUN = 25;
describe('datatype', () => {
seededTests(faker, 'datatype', (t) => {
- t.describe('number', (t) => {
- t.it('noArgs')
- .itRepeated('repeated', 5, 6)
- .it('with min', { min: -42 })
- .it('with max', { max: 69 })
- .it('with min and max', {
- min: -42,
- max: 69,
- })
- .it('with min, max and precision', {
- min: -42,
- max: 69,
- precision: 0.01,
- });
- });
-
- t.describe('float', (t) => {
- t.it('noArgs')
- .itRepeated('repeated', 6)
- .it('with min', { min: -42 })
- .it('with max', { max: 69 })
- .it('with min and max', { min: -42, max: 69 })
- .it('with min, max and precision', {
- min: -42,
- max: 69,
- precision: 0.0001,
- });
- });
-
- t.describe('datetime', (t) => {
- t.it('noArgs')
- .it('with given number', Date.parse('2001-04-03T23:21:10.773Z'))
- .it('with min', {
- min: Date.parse('1622-05-23T13:45:08.843Z'),
- })
- .it('with max', {
- max: Date.parse('2002-01-29T19:47:52.605Z'),
- })
- .it('with min and max', {
- min: Date.parse('1622-05-23T13:45:08.843Z'),
- max: Date.parse('1802-01-29T19:47:52.605Z'),
- });
- });
-
- t.describe('string', (t) => {
- t.it('noArgs')
- .it('with number', 42)
- .it('with length option', { length: 22 });
- });
-
- t.itRepeated('uuid', 5);
-
t.describe('boolean', (t) => {
t.itRepeated('noArgs', 5)
.it('with probability', 0.42)
.it('with probability option', { probability: 0.13 });
});
-
- t.describe('hexadecimal', (t) => {
- t.it('noArgs')
- .it('with length', { length: 42 })
- .it('with prefix', { prefix: '0x' })
- .it('with casing', { case: 'lower' })
- .it('with length, prefix, and casing', {
- length: 20,
- prefix: '0x',
- case: 'lower',
- });
- });
-
- t.it('json');
-
- t.describe('array', (t) => {
- t.it('noArgs')
- .it('with length', 4)
- .it('with length range', { min: 3, max: 5 });
- });
-
- t.describe('bigInt', (t) => {
- t.it('noArgs').it('with value', 42);
- });
});
describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))(
'random seeded tests for seed %i',
() => {
- describe('number', () => {
- it('should return a random number given a maximum value as Number', () => {
- const max = 10;
-
- const actual = faker.datatype.number(max);
-
- expect(actual).toBeGreaterThanOrEqual(0);
- expect(actual).toBeLessThanOrEqual(max);
- });
-
- it('should return a random number given a maximum value as Object', () => {
- const options = { max: 10 };
-
- const actual = faker.datatype.number(options);
-
- expect(actual).toBeGreaterThanOrEqual(0);
- expect(actual).toBeLessThanOrEqual(options.max);
- });
-
- it('should return a random number given a maximum value of 0', () => {
- const options = { max: 0 };
-
- const actual = faker.datatype.number(options);
-
- expect(actual).toBe(0);
- });
-
- it('should return a random number given a negative number minimum and maximum value of 0', () => {
- const options = { min: -100, max: 0 };
-
- const actual = faker.datatype.number(options);
-
- expect(actual).toBeGreaterThanOrEqual(options.min);
- expect(actual).toBeLessThanOrEqual(options.max);
- });
-
- it('should return a random number between a range', () => {
- const options = { min: 22, max: 33 };
- for (let i = 0; i < 100; i++) {
- const actual = faker.datatype.number(options);
- expect(actual).toBeGreaterThanOrEqual(options.min);
- expect(actual).toBeLessThanOrEqual(options.max);
- }
- });
-
- it('should return inclusive negative max value', () => {
- let foundNegative4 = false;
- let foundNegative5 = false;
-
- for (let iter = 0; iter < 1000; iter++) {
- const actual = faker.datatype.number({ min: -5, max: -4 });
-
- if (actual === -4) {
- foundNegative4 = true;
- } else if (actual === -5) {
- foundNegative5 = true;
- }
-
- expect(actual).toBeGreaterThanOrEqual(-5);
- expect(actual).toBeLessThanOrEqual(-4);
-
- if (foundNegative4 && foundNegative5) {
- break;
- }
- }
-
- expect(foundNegative4).toBeTruthy();
- expect(foundNegative5).toBeTruthy();
- });
-
- it('provides numbers with a given precision of 0.5 steps', () => {
- const results = [
- ...new Set(
- Array.from({ length: 50 }, () =>
- faker.datatype.float({
- min: 0,
- max: 1.5,
- precision: 0.5,
- })
- )
- ),
- ].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 = [
- ...new Set(
- Array.from({ length: 50 }, () =>
- faker.datatype.float({
- min: 0,
- max: 1.9,
- precision: 0.4,
- })
- )
- ),
- ].sort();
-
- expect(results).toEqual([0, 0.4, 0.8, 1.2, 1.6]);
- });
-
- it('provides numbers with a with exact precision', () => {
- const options = { min: 0.5, max: 0.99, precision: 0.01 };
- for (let i = 0; i < 100; i++) {
- const actual = faker.datatype.number(options);
- expect(actual).toBe(Number(actual.toFixed(2)));
- }
- });
-
- it('should not mutate the input object', () => {
- const initialMin = 1;
- const initialPrecision = 1;
- const initialOtherProperty = 'hello darkness my old friend';
- const input: {
- min?: number;
- max?: number;
- precision?: number;
- otherProperty: string;
- } = Object.freeze({
- min: initialMin,
- precision: initialPrecision,
- otherProperty: initialOtherProperty,
- });
-
- expect(() => faker.datatype.number(input)).not.toThrow();
- });
-
- it('should throw when min > max', () => {
- const min = 10;
- const max = 9;
-
- expect(() => {
- faker.datatype.number({ min, max });
- }).toThrow(
- new FakerError(`Max ${max} should be greater than min ${min}.`)
- );
- });
-
- it('should throw when precision is negative', () => {
- expect(() => {
- faker.datatype.number({ precision: -0.01 });
- }).toThrow(
- new FakerError('multipleOf/precision should be greater than 0.')
- );
- });
- });
-
- describe('float', () => {
- it('should return a random float with a default precision value (0.01)', () => {
- const number = faker.datatype.float();
- expect(number).toBe(Number(number.toFixed(2)));
- });
-
- it('should return a random float given a precision value', () => {
- const number = faker.datatype.float(0.001);
- expect(number).toBe(Number(number.toFixed(3)));
- });
-
- it('should return a random number given a maximum value as Object', () => {
- const options = { max: 10 };
- expect(faker.datatype.float(options)).toBeGreaterThanOrEqual(0);
- expect(faker.datatype.float(options)).toBeLessThanOrEqual(
- options.max
- );
- });
-
- it('should return a random number given a maximum value of 0', () => {
- const options = { max: 0 };
- expect(faker.datatype.float(options)).toBe(0);
- });
-
- it('should return a random number given a negative number minimum and maximum value of 0', () => {
- const options = { min: -100, max: 0 };
- expect(faker.datatype.float(options)).toBeGreaterThanOrEqual(
- options.min
- );
- expect(faker.datatype.float(options)).toBeLessThanOrEqual(
- options.max
- );
- });
-
- it('should return a random number between a range', () => {
- const options = { min: 22, max: 33 };
- for (let i = 0; i < 5; i++) {
- const randomNumber = faker.datatype.float(options);
- expect(randomNumber).toBeGreaterThanOrEqual(options.min);
- expect(randomNumber).toBeLessThanOrEqual(options.max);
- }
- });
-
- it('provides numbers with a given precision', () => {
- const options = { min: 0, max: 1.5, precision: 0.5 };
- const results = [
- ...new Set(
- Array.from({ length: 50 }, () => faker.datatype.float(options))
- ),
- ].sort();
-
- expect(results).toEqual([0, 0.5, 1, 1.5]);
- });
-
- it('provides numbers with a with exact precision', () => {
- const options = { min: 0.5, max: 0.99, precision: 0.01 };
- for (let i = 0; i < 100; i++) {
- const number = faker.datatype.float(options);
- expect(number).toBe(Number(number.toFixed(2)));
- }
- });
-
- it('should not modify the input object', () => {
- const min = 1;
- const max = 2;
- const opts = { min, max };
-
- faker.datatype.float(opts);
-
- expect(opts.min).toBe(min);
- expect(opts.max).toBe(max);
- });
-
- it('should throw when min > max', () => {
- const min = 10;
- const max = 9;
-
- expect(() => {
- faker.datatype.float({ min, max });
- }).toThrow(
- new FakerError(`Max ${max} should be greater than min ${min}.`)
- );
- });
-
- it('should throw when precision <= 0', () => {
- const min = 1;
- const max = 2;
-
- expect(() => {
- faker.datatype.float({ min, max, precision: 0 });
- }).toThrow(
- new FakerError('multipleOf/precision should be greater than 0.')
- );
- expect(() => {
- faker.datatype.float({ min, max, precision: -1 });
- }).toThrow(
- new FakerError('multipleOf/precision should be greater than 0.')
- );
- });
- });
-
- describe('datetime', () => {
- it('check validity of date and if returned value is created by Date()', () => {
- const date = faker.datatype.datetime();
- expect(date).toBeTypeOf('object');
- expect(date.getTime()).not.toBeNaN();
- expect(Object.prototype.toString.call(date)).toBe('[object Date]');
- });
- });
-
- describe('string', () => {
- it('should generate a string value', () => {
- const generatedString = faker.datatype.string();
- expect(generatedString).toBeTypeOf('string');
- expect(generatedString).toHaveLength(10);
- });
-
- it('should return empty string if negative length is passed', () => {
- const negativeValue = faker.datatype.number({ min: -1000, max: -1 });
- const generatedString = faker.datatype.string(negativeValue);
- expect(generatedString).toBe('');
- expect(generatedString).toHaveLength(0);
- });
- });
-
describe('boolean', () => {
it('generates a boolean value', () => {
const bool = faker.datatype.boolean();
@@ -424,160 +74,6 @@ describe('datatype', () => {
expect(() => faker.datatype.boolean(emptyOptions)).not.toThrow();
});
});
-
- describe('UUID', () => {
- it('generates a valid UUID', () => {
- const UUID = faker.datatype.uuid();
- const RFC4122 =
- /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
- expect(UUID).toMatch(RFC4122);
- });
- });
-
- describe('hexadecimal', () => {
- it('generates single hex character when no additional argument was provided', () => {
- const hex = faker.datatype.hexadecimal();
- expect(hex).toMatch(/^(0x)[0-9a-f]{1}$/i);
- expect(hex.substring(2)).toHaveLength(1);
- });
-
- it('generates a hex string with a provided prefix', () => {
- const hex = faker.datatype.hexadecimal({ prefix: '0x' });
- expect(hex).toMatch(/^(0x)[0-9A-F]+$/i);
- expect(hex).toHaveLength(3);
- });
-
- it('generates a random hex string with a provided length', () => {
- const hex = faker.datatype.hexadecimal({ length: 5 });
- expect(hex).toMatch(/^(0x)[0-9a-f]+$/i);
- expect(hex.substring(2)).toHaveLength(5);
- });
-
- it('generates a hex string with a provided casing', () => {
- const hex = faker.datatype.hexadecimal({ case: 'lower' });
- expect(hex).toMatch(/^(0x)[0-9a-f]+$/i);
- expect(hex.substring(2)).toHaveLength(1);
- });
-
- it('generates a hex string with a provided prefix, length, and casing', () => {
- const hex = faker.datatype.hexadecimal({
- prefix: '0x',
- length: 7,
- case: 'upper',
- });
- expect(hex).toMatch(/^(0x)[0-9A-F]+$/i);
- expect(hex.substring(2)).toHaveLength(7);
- });
- });
-
- describe('json', () => {
- it('generates a valid json object', () => {
- const jsonObject = faker.datatype.json();
- expect(jsonObject).toBeTypeOf('string');
- expect(JSON.parse(jsonObject)).toBeTruthy();
- });
- });
-
- describe('array', () => {
- it('generates an array with passed size', () => {
- const randomSize = faker.datatype.number();
- const generatedArray = faker.datatype.array(randomSize);
- expect(generatedArray).toHaveLength(randomSize);
- });
-
- it('generates an array with 0 element', () => {
- const generatedArray = faker.datatype.array(0);
- expect(generatedArray).toHaveLength(0);
- });
-
- it('generates an array with 1 element', () => {
- const generatedArray = faker.datatype.array(1);
- expect(generatedArray).toHaveLength(1);
- });
-
- it('generates an array with length range', () => {
- const generatedArray = faker.datatype.array({ min: 1, max: 5 });
- expect(generatedArray.length).toBeGreaterThanOrEqual(1);
- expect(generatedArray.length).toBeLessThanOrEqual(5);
- });
- });
-
- describe('bigInt', () => {
- it('should generate a bigInt value', () => {
- const generateBigInt = faker.datatype.bigInt();
- expect(generateBigInt).toBeTypeOf('bigint');
- });
-
- it('should generate a big bigInt value with low delta', () => {
- const min = 999999999n;
- const max = 1000000000n;
- const generateBigInt = faker.datatype.bigInt({ min, max });
- expect(generateBigInt).toBeTypeOf('bigint');
- expect(generateBigInt).toBeGreaterThanOrEqual(min);
- expect(generateBigInt).toBeLessThanOrEqual(max);
- });
-
- it('should return a random bigint given a maximum value as BigInt', () => {
- const max = 10n;
- expect(faker.datatype.bigInt(max)).toBeGreaterThanOrEqual(0n);
- expect(faker.datatype.bigInt(max)).toBeLessThanOrEqual(max);
- });
-
- it('should return a random bigint given a maximum value as Object', () => {
- const options = { max: 10n };
- expect(faker.datatype.bigInt(options)).toBeGreaterThanOrEqual(0n);
- expect(faker.datatype.bigInt(options)).toBeLessThanOrEqual(
- options.max
- );
- });
-
- it('should return a random bigint given a maximum value of 0', () => {
- const options = { max: 0n };
- expect(faker.datatype.bigInt(options)).toBe(0n);
- });
-
- it('should return a random bigint given a negative bigint minimum and maximum value of 0', () => {
- const options = { min: -100n, max: 0n };
- expect(faker.datatype.bigInt(options)).toBeGreaterThanOrEqual(
- options.min
- );
- expect(faker.datatype.bigInt(options)).toBeLessThanOrEqual(
- options.max
- );
- });
-
- it('should return a random bigint between a range', () => {
- const options = { min: 22, max: 33 };
- for (let i = 0; i < 100; i++) {
- const randomBigInt = faker.datatype.bigInt(options);
- expect(randomBigInt).toBeGreaterThanOrEqual(options.min);
- expect(randomBigInt).toBeLessThanOrEqual(options.max);
- }
- });
-
- it('should succeed with success-rate', () => {
- const min = 0n;
- const max = 1000000000000n;
- const randomBigInt = faker.datatype.bigInt({ min, max });
- expect(randomBigInt).toBeGreaterThanOrEqual(min);
- expect(randomBigInt).toBeLessThanOrEqual(max);
- });
-
- it('should not mutate the input object', () => {
- const initialMin = 1n;
- const initialOtherProperty = 'hello darkness my old friend';
- const input: {
- min?: bigint;
- max?: bigint;
- otherProperty: string;
- } = Object.freeze({
- min: initialMin,
- otherProperty: initialOtherProperty,
- });
-
- expect(() => faker.datatype.bigInt(input)).not.toThrow();
- });
- });
}
);
});
diff --git a/test/modules/helpers.spec.ts b/test/modules/helpers.spec.ts
index 6163a0d2..c389fa8e 100644
--- a/test/modules/helpers.spec.ts
+++ b/test/modules/helpers.spec.ts
@@ -173,9 +173,9 @@ describe('helpers', () => {
});
t.describe('multiple', (t) => {
- t.it('with only method', faker.datatype.number)
- .it('with method and count', faker.datatype.number, { count: 5 })
- .it('with method and count range', faker.datatype.number, {
+ t.it('with only method', faker.number.int)
+ .it('with method and count', faker.number.int, { count: 5 })
+ .it('with method and count range', faker.number.int, {
count: { min: 1, max: 10 },
});
});