Test with a default parameter.
", - "examples": "faker.defaultBooleanParamMethod(c: boolean = true): number
+ "examples": "tsfaker.defaultBooleanParamMethod(c: boolean = true): number
",
"name": "defaultBooleanParamMethod",
@@ -51,7 +51,7 @@ exports[`signature > analyzeSignature() > functionParamMethod 1`] = `
"deprecated": false,
"description": "Test with a function parameters.
",
- "examples": "tsfaker.functionParamMethod(fn: (a: string) => number): number
+ "examples": "tsfaker.functionParamMethod(fn: (a: string) => number): number
",
"name": "functionParamMethod",
@@ -76,7 +76,7 @@ exports[`signature > analyzeSignature() > literalUnionParamMethod 1`] = `
"deprecated": false,
"description": "Test with LiteralUnion.
",
- "examples": "tsfaker.literalUnionParamMethod(value: 'a' | 'b' | string): string
+ "examples": "tsfaker.literalUnionParamMethod(value: 'a' | 'b' | string): string
",
"name": "literalUnionParamMethod",
@@ -101,7 +101,7 @@ exports[`signature > analyzeSignature() > methodWithDeprecated 1`] = `
"deprecated": true,
"description": "Test with deprecated and see marker.
",
- "examples": "tsfaker.methodWithDeprecated(): number
+ "examples": "tsfaker.methodWithDeprecated(): number
",
"name": "methodWithDeprecated",
@@ -120,8 +120,8 @@ exports[`signature > analyzeSignature() > methodWithExample 1`] = `
"deprecated": false,
"description": "Test with example marker.
",
- "examples": "tsfaker.methodWithExample(): number
-test.apidoc.methodWithExample() // 0
+ "examples": "tsfaker.methodWithExample(): number
+test.apidoc.methodWithExample() // 0
",
"name": "methodWithExample",
@@ -138,7 +138,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkers 1`] = `
"deprecated": false,
"description": "Test with multiple see markers.
",
- "examples": "tsfaker.methodWithMultipleSeeMarkers(): number
+ "examples": "tsfaker.methodWithMultipleSeeMarkers(): number
",
"name": "methodWithMultipleSeeMarkers",
@@ -158,7 +158,7 @@ exports[`signature > analyzeSignature() > methodWithSinceMarker 1`] = `
"deprecated": false,
"description": "Test with since marker.
",
- "examples": "tsfaker.methodWithSinceMarker(): number
+ "examples": "tsfaker.methodWithSinceMarker(): number
",
"name": "methodWithSinceMarker",
@@ -175,7 +175,7 @@ exports[`signature > analyzeSignature() > multiParamMethod 1`] = `
"deprecated": false,
"description": "Test with multiple parameters.
",
- "examples": "tsfaker.multiParamMethod(a: number, b?: string, c: boolean = true): number
+ "examples": "tsfaker.multiParamMethod(a: number, b?: string, c: boolean = true): number
",
"name": "multiParamMethod",
@@ -214,7 +214,7 @@ exports[`signature > analyzeSignature() > noParamMethod 1`] = `
"deprecated": false,
"description": "Test with no parameters.
",
- "examples": "tsfaker.noParamMethod(): number
+ "examples": "tsfaker.noParamMethod(): number
",
"name": "noParamMethod",
@@ -231,7 +231,7 @@ exports[`signature > analyzeSignature() > optionalStringParamMethod 1`] = `
"deprecated": false,
"description": "Test with an optional parameter.
",
- "examples": "tsfaker.optionalStringParamMethod(b?: string): number
+ "examples": "tsfaker.optionalStringParamMethod(b?: string): number
",
"name": "optionalStringParamMethod",
@@ -256,13 +256,13 @@ exports[`signature > analyzeSignature() > optionsInlineParamMethodWithDefaults 1
"deprecated": false,
"description": "Test with a function parameters (inline types) with defaults.
",
- "examples": "tsfaker.optionsInlineParamMethodWithDefaults(a: {
- value: number
-} = { value: 1 }, b: {
- value: number
-} = { value: 1 }, c: {
- value: number
-}): number
+ "examples": "tsfaker.optionsInlineParamMethodWithDefaults(a: {
+ value: number
+} = { value: 1 }, b: {
+ value: number
+} = { value: 1 }, c: {
+ value: number
+}): number
",
"name": "optionsInlineParamMethodWithDefaults",
@@ -324,7 +324,7 @@ exports[`signature > analyzeSignature() > optionsInterfaceParamMethodWithDefault
"deprecated": false,
"description": "Test with a function parameters with defaults.
",
- "examples": "tsfaker.optionsInterfaceParamMethodWithDefaults(a: ParameterOptionsInterfaceA = { value: 1 }, b: ParameterOptionsInterfaceB = { value: 1 }, c: ParameterOptionsInterfaceC): number
+ "examples": "tsfaker.optionsInterfaceParamMethodWithDefaults(a: ParameterOptionsInterfaceA = { value: 1 }, b: ParameterOptionsInterfaceB = { value: 1 }, c: ParameterOptionsInterfaceC): number
",
"name": "optionsInterfaceParamMethodWithDefaults",
@@ -363,12 +363,12 @@ exports[`signature > analyzeSignature() > optionsParamMethod 1`] = `
"deprecated": false,
"description": "Test with a function parameters.
",
- "examples": "tsfaker.optionsParamMethod(options: {
- a: number,
- b: string,
- c: boolean,
- d: () => string
-}): number
+ "examples": "tsfaker.optionsParamMethod(options: {
+ a: number,
+ b: string,
+ c: boolean,
+ d: () => string
+}): number
",
"name": "optionsParamMethod",
@@ -421,7 +421,7 @@ exports[`signature > analyzeSignature() > optionsTypeParamMethodWithDefaults 1`]
"deprecated": false,
"description": "Test with a function parameters with defaults.
",
- "examples": "tsfaker.optionsTypeParamMethodWithDefaults(a: ParameterOptionsTypeA = { value: 1 }, b: ParameterOptionsTypeB = { value: 1 }, c: ParameterOptionsTypeC): number
+ "examples": "tsfaker.optionsTypeParamMethodWithDefaults(a: ParameterOptionsTypeA = { value: 1 }, b: ParameterOptionsTypeB = { value: 1 }, c: ParameterOptionsTypeC): number
",
"name": "optionsTypeParamMethodWithDefaults",
@@ -460,7 +460,7 @@ exports[`signature > analyzeSignature() > requiredNumberParamMethod 1`] = `
"deprecated": false,
"description": "Test with a required parameter.
",
- "examples": "tsfaker.requiredNumberParamMethod(a: number): number
+ "examples": "tsfaker.requiredNumberParamMethod(a: number): number
",
"name": "requiredNumberParamMethod",
@@ -485,7 +485,7 @@ exports[`signature > analyzeSignature() > stringUnionParamMethod 1`] = `
"deprecated": false,
"description": "Test with string union.
",
- "examples": "tsfaker.stringUnionParamMethod(value: 'a' | 'b'): string
+ "examples": "tsfaker.stringUnionParamMethod(value: 'a' | 'b'): string
",
"name": "stringUnionParamMethod",
diff --git a/test/string.spec.ts b/test/string.spec.ts
index 6d34f098653..32dc2ddfefc 100644
--- a/test/string.spec.ts
+++ b/test/string.spec.ts
@@ -11,6 +11,7 @@ describe('string', () => {
t.it('noArgs')
.itRepeated('with length parameter', 5, 5)
.it('with length', { length: 6 })
+ .it('with length range', { length: { min: 10, max: 20 } })
.it('with casing = lower', { casing: 'lower' })
.it('with casing = upper', { casing: 'upper' })
.it('with casing = mixed', { casing: 'mixed' })
@@ -26,6 +27,7 @@ describe('string', () => {
t.it('noArgs')
.itRepeated('with length parameter', 5, 5)
.it('with length', { length: 6 })
+ .it('with length range', { length: { min: 10, max: 20 } })
.it('with casing = lower', { casing: 'lower' })
.it('with casing = upper', { casing: 'upper' })
.it('with casing = mixed', { casing: 'mixed' })
@@ -40,6 +42,7 @@ describe('string', () => {
t.describe('hexadecimal', (t) => {
t.it('noArgs')
.it('with length', { length: 6 })
+ .it('with length range', { length: { min: 10, max: 20 } })
.it('with casing = lower', { casing: 'lower' })
.it('with casing = upper', { casing: 'upper' })
.it('with casing = mixed', { casing: 'mixed' })
@@ -55,6 +58,7 @@ describe('string', () => {
t.it('noArgs')
.itRepeated('with length parameter', 5, 5)
.it('with length', { length: 6 })
+ .it('with length range', { length: { min: 10, max: 20 } })
.it('with allowLeadingZeros', { allowLeadingZeros: true })
.it('with exclude', { exclude: '12345' })
.it('with length, allowLeadingZeros and exclude', {
@@ -65,7 +69,9 @@ describe('string', () => {
});
t.describe('sample', (t) => {
- t.it('noArgs').itRepeated('with length parameter', 5, 5);
+ t.it('noArgs')
+ .itRepeated('with length parameter', 5, 5)
+ .it('with length range', { min: 10, max: 20 });
});
t.itRepeated('uuid', 5);
@@ -95,7 +101,7 @@ describe('string', () => {
expect(actual).toMatch(pattern);
});
- it('should generate many random letters', () => {
+ it('should generate 5 random letters', () => {
const actual = faker.string.alpha(5);
expect(actual).toHaveLength(5);
@@ -110,6 +116,16 @@ describe('string', () => {
}
);
+ it('should return a random amount of characters', () => {
+ const actual = faker.string.alpha({ length: { min: 10, max: 20 } });
+
+ expect(actual).toBeTruthy();
+ expect(actual).toBeTypeOf('string');
+
+ expect(actual.length).toBeGreaterThanOrEqual(10);
+ expect(actual.length).toBeLessThanOrEqual(20);
+ });
+
it('should be able to ban some characters', () => {
const actual = faker.string.alpha({
length: 5,
@@ -190,7 +206,7 @@ describe('string', () => {
expect(actual).toMatch(pattern);
});
- it('should generate many random characters', () => {
+ it('should generate 5 random characters', () => {
const actual = faker.string.alphanumeric(5);
expect(actual).toHaveLength(5);
@@ -205,6 +221,18 @@ describe('string', () => {
}
);
+ it('should return a random amount of characters', () => {
+ const actual = faker.string.alphanumeric({
+ length: { min: 10, max: 20 },
+ });
+
+ expect(actual).toBeTruthy();
+ expect(actual).toBeTypeOf('string');
+
+ expect(actual.length).toBeGreaterThanOrEqual(10);
+ expect(actual.length).toBeLessThanOrEqual(20);
+ });
+
it('should be able to ban all alphabetic characters', () => {
const exclude = 'abcdefghijklmnopqrstuvwxyz'.split('');
const alphaText = faker.string.alphanumeric({
@@ -325,6 +353,28 @@ describe('string', () => {
expect(hex).toMatch(/^[0-9a-f]*$/i);
expect(hex).toHaveLength(5);
});
+
+ it.each([0, -1, -100])(
+ 'should return the prefix when length is <= 0',
+ (length) => {
+ const actual = faker.string.hexadecimal({ length });
+
+ expect(actual).toBe('0x');
+ }
+ );
+
+ it('should return a random amount of characters', () => {
+ const actual = faker.string.hexadecimal({
+ length: { min: 10, max: 20 },
+ prefix: '',
+ });
+
+ expect(actual).toBeTruthy();
+ expect(actual).toBeTypeOf('string');
+
+ expect(actual.length).toBeGreaterThanOrEqual(10);
+ expect(actual.length).toBeLessThanOrEqual(20);
+ });
});
describe('numeric', () => {
@@ -345,6 +395,18 @@ describe('string', () => {
}
);
+ it('should return a random amount of characters', () => {
+ const actual = faker.string.numeric({
+ length: { min: 10, max: 20 },
+ });
+
+ expect(actual).toBeTruthy();
+ expect(actual).toBeTypeOf('string');
+
+ expect(actual.length).toBeGreaterThanOrEqual(10);
+ expect(actual.length).toBeLessThanOrEqual(20);
+ });
+
it('should return empty string with a length of 0', () => {
const actual = faker.string.numeric(0);
@@ -468,6 +530,16 @@ describe('string', () => {
const generatedString = faker.string.sample(length);
expect(generatedString).toHaveLength(length);
});
+
+ it('should return a random amount of characters', () => {
+ const actual = faker.string.sample({ min: 10, max: 20 });
+
+ expect(actual).toBeTruthy();
+ expect(actual).toBeTypeOf('string');
+
+ expect(actual.length).toBeGreaterThanOrEqual(10);
+ expect(actual.length).toBeLessThanOrEqual(20);
+ });
});
describe(`uuid`, () => {
diff --git a/test/system.spec.ts b/test/system.spec.ts
index 7d45f198ee2..7a566b2160e 100644
--- a/test/system.spec.ts
+++ b/test/system.spec.ts
@@ -38,7 +38,11 @@ describe('system', () => {
);
t.describe('fileName', (t) => {
- t.it('noArgs').it('with extensionCount', { extensionCount: 2 });
+ t.it('noArgs')
+ .it('with extensionCount', { extensionCount: 2 })
+ .it('with extensionCount range', {
+ extensionCount: { min: 0, max: 2 },
+ });
});
t.describe('commonFileName', (t) => {
@@ -275,6 +279,20 @@ describe('system', () => {
expect(parts).length(extensionCount + 1);
}
);
+
+ it('should return a random amount of file extensions', () => {
+ const actual = faker.system.fileName({
+ extensionCount: { min: 2, max: 5 },
+ });
+
+ expect(actual).toBeTruthy();
+ expect(actual).toBeTypeOf('string');
+
+ const parts = actual.split('.');
+
+ expect(parts.length, actual).toBeGreaterThanOrEqual(3);
+ expect(parts.length, actual).toBeLessThanOrEqual(6);
+ });
});
describe('filePath()', () => {
@@ -421,7 +439,7 @@ describe('system', () => {
);
it('should return non-standard cron expressions', () => {
- const validResults = ['1', '2', '3', '5', '*', '@'];
+ const validResults = ['1', '2', '3', '4', '5', '*', '@'];
expect(
faker.system.cron({ includeNonStandard: true })[0],
'generated cron, string should contain non-standard cron labels'
diff --git a/test/word.spec.ts b/test/word.spec.ts
index 1300c00a658..14ac3aaebba 100644
--- a/test/word.spec.ts
+++ b/test/word.spec.ts
@@ -31,8 +31,13 @@ describe('word', () => {
strategy: 'closest',
});
});
+
t.describe('words', (t) => {
- t.it('noArgs').it('with count = 10', 10);
+ t.it('noArgs')
+ .it('with count = 10', 10)
+ .it('with count = 20', 20)
+ .it('with options.count', { count: 10 })
+ .it('with options.count range', { count: { min: 18, max: 20 } });
});
});