Skip to content

Commit ae38b18

Browse files
spokodevST-DDT
andauthored
docs(lorem): document the fail default strategy for word (#3944)
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
1 parent 1ce5994 commit ae38b18

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/modules/lorem/module.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ export class LoremModule extends ModuleBase {
1919
*
2020
* @param options The expected length of the word or the options to use.
2121
* @param options.length The expected length of the word.
22-
* @param options.strategy The strategy to apply when no words with a matching length are found.
23-
*
24-
* Defaults to `'any-length'`.
22+
* @param options.strategy The strategy to apply when no words with a matching length are found. Defaults to `'fail'`.
2523
*
2624
* @example
2725
* faker.lorem.word() // 'temporibus'
@@ -38,13 +36,13 @@ export class LoremModule extends ModuleBase {
3836
/**
3937
* The expected length of the word.
4038
*
41-
* @default 1
39+
* If not provided, a word of any length is returned.
4240
*/
4341
length?: NumberOrRange;
4442
/**
4543
* The strategy to apply when no words with a matching length are found.
4644
*
47-
* @default 'any-length'
45+
* @default 'fail'
4846
*/
4947
strategy?: LengthStrategyType;
5048
} = {}

test/modules/lorem.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ describe('lorem', () => {
5858
expect(actual).toHaveLength(length);
5959
}
6060
);
61+
62+
it('should throw by default when no word matches the requested length', () => {
63+
expect(() => faker.lorem.word({ length: 100 })).toThrow(
64+
'No words found that match the given length.'
65+
);
66+
});
6167
});
6268

6369
describe('words()', () => {

0 commit comments

Comments
 (0)