Skip to content

Commit 9459f2d

Browse files
docs: add missing throw descriptions in JSDocs (#2560)
1 parent 505f659 commit 9459f2d

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed

src/modules/datatype/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export class DatatypeModule extends SimpleModuleBase {
2020
* @param options.max Upper bound for generated number. Defaults to `min + 99999`.
2121
* @param options.precision Precision of the generated number. Defaults to `1`.
2222
*
23-
* @throws When options define `max < min`.
23+
* @throws When `min` is greater than `max`.
24+
* @throws When `precision` is negative.
2425
*
2526
* @see faker.number.int(): For generating a random integer.
2627
* @see faker.number.float(): For generating a random floating-point number.
@@ -85,6 +86,9 @@ export class DatatypeModule extends SimpleModuleBase {
8586
* @param options.max Upper bound for generated number. Defaults to `min + 99999`.
8687
* @param options.precision Precision of the generated number. Defaults to `0.01`.
8788
*
89+
* @throws When `min` is greater than `max`.
90+
* @throws When `precision` is negative.
91+
*
8892
* @see faker.number.float(): For the replacement method.
8993
*
9094
* @example

src/modules/number/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export class NumberModule extends SimpleModuleBase {
2424
* @param options.min Lower bound for generated number. Defaults to `0`.
2525
* @param options.max Upper bound for generated number. Defaults to `Number.MAX_SAFE_INTEGER`.
2626
*
27-
* @throws When options define `max < min`.
27+
* @throws When `min` is greater than `max`.
28+
* @throws When there are no integers between `min` and `max`.
2829
*
2930
* @see faker.string.numeric(): For generating a `string` of digits with a given length (range).
3031
*
@@ -93,6 +94,9 @@ export class NumberModule extends SimpleModuleBase {
9394
* @param options.precision Precision of the generated number, for example `0.01` will round to 2 decimal points.
9495
* If precision is passed, the upper bound is inclusive.
9596
*
97+
* @throws When `min` is greater than `max`.
98+
* @throws When `precision` is negative.
99+
*
96100
* @example
97101
* faker.number.float() // 0.5688541042618454
98102
* faker.number.float(3) // 2.367973240558058
@@ -168,7 +172,8 @@ export class NumberModule extends SimpleModuleBase {
168172
* @param options.min Lower bound for generated number. Defaults to `0`.
169173
* @param options.max Upper bound for generated number. Defaults to `1`.
170174
*
171-
* @throws When options define `max < min`.
175+
* @throws When `min` is greater than `max`.
176+
* @throws When there are no integers between `min` and `max`.
172177
*
173178
* @see faker.string.binary(): For generating a `binary string` with a given length (range).
174179
*
@@ -217,7 +222,8 @@ export class NumberModule extends SimpleModuleBase {
217222
* @param options.min Lower bound for generated number. Defaults to `0`.
218223
* @param options.max Upper bound for generated number. Defaults to `7`.
219224
*
220-
* @throws When options define `max < min`.
225+
* @throws When `min` is greater than `max`.
226+
* @throws When there are no integers between `min` and `max`.
221227
*
222228
* @see faker.string.octal(): For generating an `octal string` with a given length (range).
223229
*
@@ -266,7 +272,8 @@ export class NumberModule extends SimpleModuleBase {
266272
* @param options.min Lower bound for generated number. Defaults to `0`.
267273
* @param options.max Upper bound for generated number. Defaults to `15`.
268274
*
269-
* @throws When options define `max < min`.
275+
* @throws When `min` is greater than `max`.
276+
* @throws When there are no integers between `min` and `max`.
270277
*
271278
* @example
272279
* faker.number.hex() // 'b'
@@ -313,7 +320,7 @@ export class NumberModule extends SimpleModuleBase {
313320
* @param options.min Lower bound for generated bigint. Defaults to `0n`.
314321
* @param options.max Upper bound for generated bigint. Defaults to `min + 999999999999999n`.
315322
*
316-
* @throws When options define `max < min`.
323+
* @throws When `min` is greater than `max`.
317324
*
318325
* @example
319326
* faker.number.bigInt() // 55422n

test/modules/datatype.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ describe('datatype', () => {
232232
new FakerError(`Max ${max} should be greater than min ${min}.`)
233233
);
234234
});
235+
236+
it('should throw when precision is negative', () => {
237+
expect(() => {
238+
faker.datatype.number({ precision: -0.01 });
239+
}).toThrow(new FakerError('Precision should be greater than 0.'));
240+
});
235241
});
236242

237243
describe('float', () => {
@@ -306,6 +312,23 @@ describe('datatype', () => {
306312
expect(opts.min).toBe(min);
307313
expect(opts.max).toBe(max);
308314
});
315+
316+
it('should throw when min > max', () => {
317+
const min = 10;
318+
const max = 9;
319+
320+
expect(() => {
321+
faker.datatype.number({ min, max });
322+
}).toThrow(
323+
new FakerError(`Max ${max} should be greater than min ${min}.`)
324+
);
325+
});
326+
327+
it('should throw when precision is negative', () => {
328+
expect(() => {
329+
faker.datatype.float({ precision: -0.01 });
330+
}).toThrow(new FakerError('Precision should be greater than 0.'));
331+
});
309332
});
310333

311334
describe('datetime', () => {

test/modules/number.spec.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ describe('number', () => {
305305
return [...str].every((char) => char === '0' || char === '1');
306306
}
307307

308-
it('enerates single binary character when no additional argument was provided', () => {
308+
it('generates single binary character when no additional argument was provided', () => {
309309
const binary = faker.number.binary();
310310

311311
expect(binary).toBeTypeOf('string');
@@ -345,6 +345,14 @@ describe('number', () => {
345345
new FakerError(`Max ${max} should be greater than min ${min}.`)
346346
);
347347
});
348+
349+
it('should throw when there is no integer between min and max', () => {
350+
expect(() => {
351+
faker.number.binary({ min: 2.1, max: 2.9 });
352+
}).toThrow(
353+
new FakerError(`No integer value between 2.1 and 2.9 found.`)
354+
);
355+
});
348356
});
349357

350358
describe('octal', () => {
@@ -388,6 +396,14 @@ describe('number', () => {
388396
new FakerError(`Max ${max} should be greater than min ${min}.`)
389397
);
390398
});
399+
400+
it('should throw when there is no integer between min and max', () => {
401+
expect(() => {
402+
faker.number.octal({ min: 2.1, max: 2.9 });
403+
}).toThrow(
404+
new FakerError(`No integer value between 2.1 and 2.9 found.`)
405+
);
406+
});
391407
});
392408

393409
describe('hex', () => {
@@ -428,6 +444,14 @@ describe('number', () => {
428444
new FakerError(`Max ${max} should be greater than min ${min}.`)
429445
);
430446
});
447+
448+
it('should throw when there is no integer between min and max', () => {
449+
expect(() => {
450+
faker.number.hex({ min: 2.1, max: 2.9 });
451+
}).toThrow(
452+
new FakerError(`No integer value between 2.1 and 2.9 found.`)
453+
);
454+
});
431455
});
432456

433457
describe('bigInt', () => {

0 commit comments

Comments
 (0)