diff options
| author | Eric Cheng <[email protected]> | 2022-08-28 09:59:51 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-28 15:59:51 +0200 |
| commit | 379ba79ba3b9735ed039d87f32fc14fa9920d4ed (patch) | |
| tree | e2ab2bf145231bafc6aaa73ccfdd0124ee3e3c03 /test | |
| parent | f78843edb05913c44ebd86535b0d50d22e99fc5e (diff) | |
| download | faker-379ba79ba3b9735ed039d87f32fc14fa9920d4ed.tar.xz faker-379ba79ba3b9735ed039d87f32fc14fa9920d4ed.zip | |
fix(datatype): unintentional hex breaking change (#1306)
Co-authored-by: Leyla Jähnig <[email protected]>
Diffstat (limited to 'test')
| -rw-r--r-- | test/__snapshots__/datatype.spec.ts.snap | 24 | ||||
| -rw-r--r-- | test/datatype.spec.ts | 20 |
2 files changed, 25 insertions, 19 deletions
diff --git a/test/__snapshots__/datatype.spec.ts.snap b/test/__snapshots__/datatype.spec.ts.snap index 97f2d4c6..7980ec5c 100644 --- a/test/__snapshots__/datatype.spec.ts.snap +++ b/test/__snapshots__/datatype.spec.ts.snap @@ -70,11 +70,13 @@ 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`] = `"8"`; +exports[`datatype > 42 > hexadecimal > noArgs 1`] = `"0x8"`; -exports[`datatype > 42 > hexadecimal > with casing 1`] = `"8"`; +exports[`datatype > 42 > hexadecimal > with casing 1`] = `"0x8"`; -exports[`datatype > 42 > hexadecimal > with length 1`] = `"8BE4ABdd39321aD7d3fe01FfCE404F4d6db0906bd8"`; +exports[`datatype > 42 > hexadecimal > with length 1`] = `"0x8BE4ABdd39321aD7d3fe01FfCE404F4d6db0906bd8"`; + +exports[`datatype > 42 > hexadecimal > with length and casing 1`] = `"0x8be4abdd39321ad7d3fe"`; exports[`datatype > 42 > hexadecimal > with length, prefix, and casing 1`] = `"0x8be4abdd39321ad7d3fe"`; @@ -186,11 +188,13 @@ 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`] = `"E"`; +exports[`datatype > 1211 > hexadecimal > noArgs 1`] = `"0xE"`; + +exports[`datatype > 1211 > hexadecimal > with casing 1`] = `"0xe"`; -exports[`datatype > 1211 > hexadecimal > with casing 1`] = `"e"`; +exports[`datatype > 1211 > hexadecimal > with length 1`] = `"0xEaDB42F0e3f4A973fAB0AeefCE96DFCF49cD438dF9"`; -exports[`datatype > 1211 > hexadecimal > with length 1`] = `"EaDB42F0e3f4A973fAB0AeefCE96DFCF49cD438dF9"`; +exports[`datatype > 1211 > hexadecimal > with length and casing 1`] = `"0xeadb42f0e3f4a973fab0"`; exports[`datatype > 1211 > hexadecimal > with length, prefix, and casing 1`] = `"0xeadb42f0e3f4a973fab0"`; @@ -302,11 +306,13 @@ 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`] = `"5"`; +exports[`datatype > 1337 > hexadecimal > noArgs 1`] = `"0x5"`; + +exports[`datatype > 1337 > hexadecimal > with casing 1`] = `"0x5"`; -exports[`datatype > 1337 > hexadecimal > with casing 1`] = `"5"`; +exports[`datatype > 1337 > hexadecimal > with length 1`] = `"0x5c346ba075bd57F5A62B82d72AF39CBBB07a98cbA8"`; -exports[`datatype > 1337 > hexadecimal > with length 1`] = `"5c346ba075bd57F5A62B82d72AF39CBBB07a98cbA8"`; +exports[`datatype > 1337 > hexadecimal > with length and casing 1`] = `"0x5c346ba075bd57f5a62b"`; exports[`datatype > 1337 > hexadecimal > with length, prefix, and casing 1`] = `"0x5c346ba075bd57f5a62b"`; diff --git a/test/datatype.spec.ts b/test/datatype.spec.ts index a57139fd..25847e07 100644 --- a/test/datatype.spec.ts +++ b/test/datatype.spec.ts @@ -331,14 +331,8 @@ describe('datatype', () => { describe('hexadecimal', () => { it('generates single hex character when no additional argument was provided', () => { const hex = faker.datatype.hexadecimal(); - expect(hex).toMatch(/^[0-9a-f]{1}$/i); - expect(hex).toHaveLength(1); - }); - - it('generates a random hex string with a provided length', () => { - const hex = faker.datatype.hexadecimal({ length: 5 }); - expect(hex).toMatch(/^[0-9a-f]+$/i); - expect(hex).toHaveLength(5); + expect(hex).toMatch(/^(0x)[0-9a-f]{1}$/i); + expect(hex.substring(2)).toHaveLength(1); }); it('generates a hex string with a provided prefix', () => { @@ -347,10 +341,16 @@ describe('datatype', () => { 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(/^[0-9a-f]+$/i); - expect(hex).toHaveLength(1); + 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', () => { |
