diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 2da5b59f7e1..3c4eedee1d4 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -282,16 +282,16 @@ export class InternetModule { } /** - * Generates a random IPv4 address. + * Generates a random IPv4 or IPv6 address. * * @example * faker.internet.ip() // '245.108.222.0' + * faker.internet.ip() // '4e5:f9c5:4337:abfd:9caf:1135:41ad:d8d3' * * @since 2.0.1 */ ip(): string { - // TODO @Shinigami92 2022-03-21: We may want to return a IPv4 or IPv6 address here in a later major release - return this.ipv4(); + return this.faker.datatype.boolean() ? this.ipv4() : this.ipv6(); } /** diff --git a/test/__snapshots__/internet.spec.ts.snap b/test/__snapshots__/internet.spec.ts.snap index 697bc6131d9..d2c4391163f 100644 --- a/test/__snapshots__/internet.spec.ts.snap +++ b/test/__snapshots__/internet.spec.ts.snap @@ -34,7 +34,7 @@ exports[`internet > 42 > httpStatusCode > noArgs 1`] = `207`; exports[`internet > 42 > httpStatusCode > with options 1`] = `410`; -exports[`internet > 42 > ip 1`] = `"95.203.243.46"`; +exports[`internet > 42 > ip 1`] = `"cf2b:c992:7210:7d59:2ba0:0fbd:f302:f294"`; exports[`internet > 42 > ipv4 1`] = `"95.203.243.46"`; @@ -94,7 +94,7 @@ exports[`internet > 1211 > httpStatusCode > noArgs 1`] = `505`; exports[`internet > 1211 > httpStatusCode > with options 1`] = `429`; -exports[`internet > 1211 > ip 1`] = `"237.117.228.199"`; +exports[`internet > 1211 > ip 1`] = `"117.228.199.57"`; exports[`internet > 1211 > ipv4 1`] = `"237.117.228.199"`; @@ -154,7 +154,7 @@ exports[`internet > 1337 > httpStatusCode > noArgs 1`] = `205`; exports[`internet > 1337 > httpStatusCode > with options 1`] = `407`; -exports[`internet > 1337 > ip 1`] = `"67.143.40.54"`; +exports[`internet > 1337 > ip 1`] = `"8234:8705:3894:5f4b:41c6:1a52:bf27:dccc"`; exports[`internet > 1337 > ipv4 1`] = `"67.143.40.54"`; diff --git a/test/internet.spec.ts b/test/internet.spec.ts index 1dbccc23c09..cbbf2745ddd 100644 --- a/test/internet.spec.ts +++ b/test/internet.spec.ts @@ -368,9 +368,19 @@ describe('internet', () => { }); describe('ip()', () => { - it('should return a random IPv4 address with four parts', () => { + it('should return a random IPv4 or IPv6 address', () => { const ip = faker.internet.ip(); + expect(ip).toBeTruthy(); + expect(ip).toBeTypeOf('string'); + expect(ip).toSatisfy(validator.isIP); + }); + }); + + describe('ipv4()', () => { + it('should return a random IPv4 with four parts', () => { + const ip = faker.internet.ipv4(); + expect(ip).toBeTruthy(); expect(ip).toBeTypeOf('string'); expect(ip).toSatisfy((value: string) => validator.isIP(value, 4));