diff options
| -rw-r--r-- | docs/guide/upgrading.md | 26 | ||||
| -rw-r--r-- | src/modules/word/filter-word-list-by-length.ts | 4 | ||||
| -rw-r--r-- | src/modules/word/index.ts | 39 | ||||
| -rw-r--r-- | test/modules/__snapshots__/word.spec.ts.snap | 162 | ||||
| -rw-r--r-- | test/modules/word.spec.ts | 24 |
5 files changed, 109 insertions, 146 deletions
diff --git a/docs/guide/upgrading.md b/docs/guide/upgrading.md index a4296059..cea424e1 100644 --- a/docs/guide/upgrading.md +++ b/docs/guide/upgrading.md @@ -61,3 +61,29 @@ Some methods do not have exact replacements, so check your code carefully. | `faker.image.urlPlaceholder` | `faker.image.dataUri` | | `faker.finance.maskedNumber` | See [#3201](https://github.com/faker-js/faker/pull/3201) | | `faker.image.avatarLegacy` | `faker.image.avatar` | + +### Word Methods Default Resolution Strategy + +The default resolution strategy for the methods in the word module changed to 'fail'. +This means that methods in the word module will throw an error if no words for your input criteria exist. + +```ts +// There are no nouns between 20-25 characters long in the word list +faker.word.noun({ length: { min: 20, max: 25 } }); +// In v9, this would return a random noun of any length, like 'plastic' +// In v10, this throws an error `FakerError: No words found that match the given length.` +``` + +Previously, the methods would return a random word, completly ignoring the the length requirements you specified. +If you want to restore this behaviour, you can provide the 'any-length' strategy to the word methods. + +| Method in v9 | Method in v10 with v9 behaviour | +| --------------------------- | ----------------------------------------------------- | +| `faker.word.adjective()` | `faker.word.adjective({ strategy: 'any-length' })` | +| `faker.word.adverb()` | `faker.word.adverb({ strategy: 'any-length' })` | +| `faker.word.conjunction()` | `faker.word.conjunction({ strategy: 'any-length' })` | +| `faker.word.interjection()` | `faker.word.interjection({ strategy: 'any-length' })` | +| `faker.word.noun()` | `faker.word.noun({ strategy: 'any-length' })` | +| `faker.word.preposition()` | `faker.word.preposition({ strategy: 'any-length' })` | +| `faker.word.sample()` | `faker.word.sample({ strategy: 'any-length' })` | +| `faker.word.verb()` | `faker.word.verb({ strategy: 'any-length' })` | diff --git a/src/modules/word/filter-word-list-by-length.ts b/src/modules/word/filter-word-list-by-length.ts index 6c1b25bf..c4e5999e 100644 --- a/src/modules/word/filter-word-list-by-length.ts +++ b/src/modules/word/filter-word-list-by-length.ts @@ -51,7 +51,7 @@ const STRATEGIES = { * @param options The options to provide. * @param options.wordList A list of words to filter. * @param options.length The exact or the range of lengths the words should have. - * @param options.strategy The strategy to apply when no words with a matching length are found. Defaults to `'any-length'`. + * @param options.strategy The strategy to apply when no words with a matching length are found. Defaults to `'fail'`. * * Available error handling strategies: * @@ -66,7 +66,7 @@ export function filterWordListByLength(options: { length?: number | { min: number; max: number }; strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; }): string[] { - const { wordList, length, strategy = 'any-length' } = options; + const { wordList, length, strategy = 'fail' } = options; if (length != null) { const filter: (word: string) => boolean = diff --git a/src/modules/word/index.ts b/src/modules/word/index.ts index 6713eec0..cf5719b2 100644 --- a/src/modules/word/index.ts +++ b/src/modules/word/index.ts @@ -21,12 +21,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.adjective() // 'pungent' * faker.word.adjective(5) // 'slimy' - * faker.word.adjective(100) // 'complete' * faker.word.adjective({ strategy: 'shortest' }) // 'icy' * faker.word.adjective({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'distant' * @@ -62,7 +61,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -94,12 +93,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.adverb() // 'quarrelsomely' * faker.word.adverb(5) // 'madly' - * faker.word.adverb(100) // 'sadly' * faker.word.adverb({ strategy: 'shortest' }) // 'too' * faker.word.adverb({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'sweetly' * @@ -135,7 +133,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -167,12 +165,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.conjunction() // 'in order that' * faker.word.conjunction(5) // 'since' - * faker.word.conjunction(100) // 'as long as' * faker.word.conjunction({ strategy: 'shortest' }) // 'or' * faker.word.conjunction({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'hence' * @@ -208,7 +205,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -240,12 +237,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.interjection() // 'gah' * faker.word.interjection(5) // 'fooey' - * faker.word.interjection(100) // 'yowza' * faker.word.interjection({ strategy: 'shortest' }) // 'hm' * faker.word.interjection({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'boohoo' * @@ -281,7 +277,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -313,12 +309,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.noun() // 'external' * faker.word.noun(5) // 'front' - * faker.word.noun(100) // 'care' * faker.word.noun({ strategy: 'shortest' }) // 'ad' * faker.word.noun({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'average' * @@ -354,7 +349,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -386,12 +381,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.preposition() // 'without' * faker.word.preposition(5) // 'abaft' - * faker.word.preposition(100) // 'an' * faker.word.preposition({ strategy: 'shortest' }) // 'a' * faker.word.preposition({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'given' * @@ -427,7 +421,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -459,12 +453,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.verb() // 'act' * faker.word.verb(5) // 'tinge' - * faker.word.verb(100) // 'mess' * faker.word.verb({ strategy: 'shortest' }) // 'do' * faker.word.verb({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'vault' * @@ -500,7 +493,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -532,7 +525,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.sample() // 'incidentally' @@ -570,7 +563,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} diff --git a/test/modules/__snapshots__/word.spec.ts.snap b/test/modules/__snapshots__/word.spec.ts.snap index b50d91ca..833acc5c 100644 --- a/test/modules/__snapshots__/word.spec.ts.snap +++ b/test/modules/__snapshots__/word.spec.ts.snap @@ -2,11 +2,9 @@ exports[`word > 42 > adjective > noArgs 1`] = `"hospitable"`; -exports[`word > 42 > adjective > with length = 10 1`] = `"idealistic"`; +exports[`word > 42 > adjective > with length = 4 1`] = `"last"`; -exports[`word > 42 > adjective > with length = 20 1`] = `"hospitable"`; - -exports[`word > 42 > adjective > with options.length 1`] = `"idealistic"`; +exports[`word > 42 > adjective > with options.length 1`] = `"last"`; exports[`word > 42 > adjective > with options.length and options.strategy 1`] = `"inconsequential"`; @@ -14,11 +12,9 @@ exports[`word > 42 > adjective > with options.strategy 1`] = `"hot"`; exports[`word > 42 > adverb > noArgs 1`] = `"jaggedly"`; -exports[`word > 42 > adverb > with length = 10 1`] = `"generously"`; - -exports[`word > 42 > adverb > with length = 20 1`] = `"jaggedly"`; +exports[`word > 42 > adverb > with length = 4 1`] = `"less"`; -exports[`word > 42 > adverb > with options.length 1`] = `"generously"`; +exports[`word > 42 > adverb > with options.length 1`] = `"less"`; exports[`word > 42 > adverb > with options.length and options.strategy 1`] = `"enthusiastically"`; @@ -26,11 +22,9 @@ exports[`word > 42 > adverb > with options.strategy 1`] = `"not"`; exports[`word > 42 > conjunction > noArgs 1`] = `"instead"`; -exports[`word > 42 > conjunction > with length = 10 1`] = `"instead"`; +exports[`word > 42 > conjunction > with length = 4 1`] = `"once"`; -exports[`word > 42 > conjunction > with length = 20 1`] = `"instead"`; - -exports[`word > 42 > conjunction > with options.length 1`] = `"instead"`; +exports[`word > 42 > conjunction > with options.length 1`] = `"once"`; exports[`word > 42 > conjunction > with options.length and options.strategy 1`] = `"consequently"`; @@ -38,11 +32,9 @@ exports[`word > 42 > conjunction > with options.strategy 1`] = `"if"`; exports[`word > 42 > interjection > noArgs 1`] = `"yahoo"`; -exports[`word > 42 > interjection > with length = 10 1`] = `"yahoo"`; - -exports[`word > 42 > interjection > with length = 20 1`] = `"yahoo"`; +exports[`word > 42 > interjection > with length = 4 1`] = `"pfft"`; -exports[`word > 42 > interjection > with options.length 1`] = `"yahoo"`; +exports[`word > 42 > interjection > with options.length 1`] = `"pfft"`; exports[`word > 42 > interjection > with options.length and options.strategy 1`] = `"gadzooks"`; @@ -50,11 +42,9 @@ exports[`word > 42 > interjection > with options.strategy 1`] = `"ah"`; exports[`word > 42 > noun > noArgs 1`] = `"gerbil"`; -exports[`word > 42 > noun > with length = 10 1`] = `"hippodrome"`; +exports[`word > 42 > noun > with length = 4 1`] = `"fund"`; -exports[`word > 42 > noun > with length = 20 1`] = `"gerbil"`; - -exports[`word > 42 > noun > with options.length 1`] = `"hippodrome"`; +exports[`word > 42 > noun > with options.length 1`] = `"fund"`; exports[`word > 42 > noun > with options.length and options.strategy 1`] = `"cross-contamination"`; @@ -62,11 +52,9 @@ exports[`word > 42 > noun > with options.strategy 1`] = `"CD"`; exports[`word > 42 > preposition > noArgs 1`] = `"concerning"`; -exports[`word > 42 > preposition > with length = 10 1`] = `"throughout"`; - -exports[`word > 42 > preposition > with length = 20 1`] = `"concerning"`; +exports[`word > 42 > preposition > with length = 4 1`] = `"like"`; -exports[`word > 42 > preposition > with options.length 1`] = `"throughout"`; +exports[`word > 42 > preposition > with options.length 1`] = `"like"`; exports[`word > 42 > preposition > with options.length and options.strategy 1`] = `"notwithstanding"`; @@ -74,11 +62,9 @@ exports[`word > 42 > preposition > with options.strategy 1`] = `"a"`; exports[`word > 42 > sample > noArgs 1`] = `"bleakly"`; -exports[`word > 42 > sample > with length = 10 1`] = `"arrogantly"`; - -exports[`word > 42 > sample > with length = 20 1`] = `"bleakly"`; +exports[`word > 42 > sample > with length = 4 1`] = `"even"`; -exports[`word > 42 > sample > with options.length 1`] = `"arrogantly"`; +exports[`word > 42 > sample > with options.length 1`] = `"even"`; exports[`word > 42 > sample > with options.length and options.strategy 1`] = `"enthusiastically"`; @@ -86,11 +72,9 @@ exports[`word > 42 > sample > with options.strategy 1`] = `"far"`; exports[`word > 42 > verb > noArgs 1`] = `"glow"`; -exports[`word > 42 > verb > with length = 10 1`] = `"exacerbate"`; +exports[`word > 42 > verb > with length = 4 1`] = `"hole"`; -exports[`word > 42 > verb > with length = 20 1`] = `"glow"`; - -exports[`word > 42 > verb > with options.length 1`] = `"exacerbate"`; +exports[`word > 42 > verb > with options.length 1`] = `"hole"`; exports[`word > 42 > verb > with options.length and options.strategy 1`] = `"institutionalize"`; @@ -98,21 +82,17 @@ exports[`word > 42 > verb > with options.strategy 1`] = `"jot"`; exports[`word > 42 > words > noArgs 1`] = `"unnaturally dreamily"`; -exports[`word > 42 > words > with count = 10 1`] = `"bleakly custody gee psst why meh ugh utilized wherever without"`; - -exports[`word > 42 > words > with count = 20 1`] = `"bleakly custody gee psst why meh ugh utilized wherever without safe across amidst intent zowie confirm usefully impanel whoa vista"`; +exports[`word > 42 > words > with count = 4 1`] = `"bleakly custody gee psst"`; -exports[`word > 42 > words > with options.count 1`] = `"bleakly custody gee psst why meh ugh utilized wherever without"`; +exports[`word > 42 > words > with options.count 1`] = `"bleakly custody gee psst"`; exports[`word > 42 > words > with options.count range 1`] = `"unnaturally dreamily chapel mozzarella through amendment dependable brilliant indeed whenever after happily relieve although atop upon provided skyline brr"`; exports[`word > 1211 > adjective > noArgs 1`] = `"velvety"`; -exports[`word > 1211 > adjective > with length = 10 1`] = `"unpleasant"`; +exports[`word > 1211 > adjective > with length = 4 1`] = `"vain"`; -exports[`word > 1211 > adjective > with length = 20 1`] = `"velvety"`; - -exports[`word > 1211 > adjective > with options.length 1`] = `"unpleasant"`; +exports[`word > 1211 > adjective > with options.length 1`] = `"vain"`; exports[`word > 1211 > adjective > with options.length and options.strategy 1`] = `"well-documented"`; @@ -120,11 +100,9 @@ exports[`word > 1211 > adjective > with options.strategy 1`] = `"wee"`; exports[`word > 1211 > adverb > noArgs 1`] = `"viciously"`; -exports[`word > 1211 > adverb > with length = 10 1`] = `"unbearably"`; - -exports[`word > 1211 > adverb > with length = 20 1`] = `"viciously"`; +exports[`word > 1211 > adverb > with length = 4 1`] = `"well"`; -exports[`word > 1211 > adverb > with options.length 1`] = `"unbearably"`; +exports[`word > 1211 > adverb > with options.length 1`] = `"well"`; exports[`word > 1211 > adverb > with options.length and options.strategy 1`] = `"enthusiastically"`; @@ -132,11 +110,9 @@ exports[`word > 1211 > adverb > with options.strategy 1`] = `"too"`; exports[`word > 1211 > conjunction > noArgs 1`] = `"whoever"`; -exports[`word > 1211 > conjunction > with length = 10 1`] = `"whoever"`; +exports[`word > 1211 > conjunction > with length = 4 1`] = `"when"`; -exports[`word > 1211 > conjunction > with length = 20 1`] = `"whoever"`; - -exports[`word > 1211 > conjunction > with options.length 1`] = `"whoever"`; +exports[`word > 1211 > conjunction > with options.length 1`] = `"when"`; exports[`word > 1211 > conjunction > with options.length and options.strategy 1`] = `"incidentally"`; @@ -144,11 +120,9 @@ exports[`word > 1211 > conjunction > with options.strategy 1`] = `"so"`; exports[`word > 1211 > interjection > noArgs 1`] = `"er"`; -exports[`word > 1211 > interjection > with length = 10 1`] = `"er"`; - -exports[`word > 1211 > interjection > with length = 20 1`] = `"er"`; +exports[`word > 1211 > interjection > with length = 4 1`] = `"pish"`; -exports[`word > 1211 > interjection > with options.length 1`] = `"er"`; +exports[`word > 1211 > interjection > with options.length 1`] = `"pish"`; exports[`word > 1211 > interjection > with options.length and options.strategy 1`] = `"gadzooks"`; @@ -156,11 +130,9 @@ exports[`word > 1211 > interjection > with options.strategy 1`] = `"um"`; exports[`word > 1211 > noun > noArgs 1`] = `"trash"`; -exports[`word > 1211 > noun > with length = 10 1`] = `"underpants"`; - -exports[`word > 1211 > noun > with length = 20 1`] = `"trash"`; +exports[`word > 1211 > noun > with length = 4 1`] = `"tray"`; -exports[`word > 1211 > noun > with options.length 1`] = `"underpants"`; +exports[`word > 1211 > noun > with options.length 1`] = `"tray"`; exports[`word > 1211 > noun > with options.length and options.strategy 1`] = `"cross-contamination"`; @@ -168,11 +140,9 @@ exports[`word > 1211 > noun > with options.strategy 1`] = `"ad"`; exports[`word > 1211 > preposition > noArgs 1`] = `"upon"`; -exports[`word > 1211 > preposition > with length = 10 1`] = `"underneath"`; +exports[`word > 1211 > preposition > with length = 4 1`] = `"vice"`; -exports[`word > 1211 > preposition > with length = 20 1`] = `"upon"`; - -exports[`word > 1211 > preposition > with options.length 1`] = `"underneath"`; +exports[`word > 1211 > preposition > with options.length 1`] = `"vice"`; exports[`word > 1211 > preposition > with options.length and options.strategy 1`] = `"notwithstanding"`; @@ -180,11 +150,9 @@ exports[`word > 1211 > preposition > with options.strategy 1`] = `"a"`; exports[`word > 1211 > sample > noArgs 1`] = `"sneaky"`; -exports[`word > 1211 > sample > with length = 10 1`] = `"remorseful"`; - -exports[`word > 1211 > sample > with length = 20 1`] = `"sneaky"`; +exports[`word > 1211 > sample > with length = 4 1`] = `"some"`; -exports[`word > 1211 > sample > with options.length 1`] = `"remorseful"`; +exports[`word > 1211 > sample > with options.length 1`] = `"some"`; exports[`word > 1211 > sample > with options.length and options.strategy 1`] = `"well-documented"`; @@ -192,11 +160,9 @@ exports[`word > 1211 > sample > with options.strategy 1`] = `"raw"`; exports[`word > 1211 > verb > noArgs 1`] = `"transplant"`; -exports[`word > 1211 > verb > with length = 10 1`] = `"transplant"`; +exports[`word > 1211 > verb > with length = 4 1`] = `"warp"`; -exports[`word > 1211 > verb > with length = 20 1`] = `"transplant"`; - -exports[`word > 1211 > verb > with options.length 1`] = `"transplant"`; +exports[`word > 1211 > verb > with options.length 1`] = `"warp"`; exports[`word > 1211 > verb > with options.length and options.strategy 1`] = `"internationalize"`; @@ -204,21 +170,17 @@ exports[`word > 1211 > verb > with options.strategy 1`] = `"tut"`; exports[`word > 1211 > words > noArgs 1`] = `"happy unnaturally phew"`; -exports[`word > 1211 > words > with count = 10 1`] = `"sneaky jam-packed willow gracefully if disarm ha furthermore nor trustworthy"`; - -exports[`word > 1211 > words > with count = 20 1`] = `"sneaky jam-packed willow gracefully if disarm ha furthermore nor trustworthy ugh fooey yippee untrue discrete tool untidy trench although radiant"`; +exports[`word > 1211 > words > with count = 4 1`] = `"sneaky jam-packed willow gracefully"`; -exports[`word > 1211 > words > with options.count 1`] = `"sneaky jam-packed willow gracefully if disarm ha furthermore nor trustworthy"`; +exports[`word > 1211 > words > with options.count 1`] = `"sneaky jam-packed willow gracefully"`; exports[`word > 1211 > words > with options.count range 1`] = `"happy unnaturally phew sedately converse horn consistency pinion so elderly when thorn object muted via mythology compassionate crushing fairly parched"`; exports[`word > 1337 > adjective > noArgs 1`] = `"fatal"`; -exports[`word > 1337 > adjective > with length = 10 1`] = `"elliptical"`; +exports[`word > 1337 > adjective > with length = 4 1`] = `"fake"`; -exports[`word > 1337 > adjective > with length = 20 1`] = `"fatal"`; - -exports[`word > 1337 > adjective > with options.length 1`] = `"elliptical"`; +exports[`word > 1337 > adjective > with options.length 1`] = `"fake"`; exports[`word > 1337 > adjective > with options.length and options.strategy 1`] = `"black-and-white"`; @@ -226,11 +188,9 @@ exports[`word > 1337 > adjective > with options.strategy 1`] = `"far"`; exports[`word > 1337 > adverb > noArgs 1`] = `"frankly"`; -exports[`word > 1337 > adverb > with length = 10 1`] = `"enormously"`; - -exports[`word > 1337 > adverb > with length = 20 1`] = `"frankly"`; +exports[`word > 1337 > adverb > with length = 4 1`] = `"less"`; -exports[`word > 1337 > adverb > with options.length 1`] = `"enormously"`; +exports[`word > 1337 > adverb > with options.length 1`] = `"less"`; exports[`word > 1337 > adverb > with options.length and options.strategy 1`] = `"enthusiastically"`; @@ -238,11 +198,9 @@ exports[`word > 1337 > adverb > with options.strategy 1`] = `"far"`; exports[`word > 1337 > conjunction > noArgs 1`] = `"how"`; -exports[`word > 1337 > conjunction > with length = 10 1`] = `"how"`; - -exports[`word > 1337 > conjunction > with length = 20 1`] = `"how"`; +exports[`word > 1337 > conjunction > with length = 4 1`] = `"once"`; -exports[`word > 1337 > conjunction > with options.length 1`] = `"how"`; +exports[`word > 1337 > conjunction > with options.length 1`] = `"once"`; exports[`word > 1337 > conjunction > with options.length and options.strategy 1`] = `"consequently"`; @@ -250,11 +208,9 @@ exports[`word > 1337 > conjunction > with options.strategy 1`] = `"if"`; exports[`word > 1337 > interjection > noArgs 1`] = `"ew"`; -exports[`word > 1337 > interjection > with length = 10 1`] = `"ew"`; +exports[`word > 1337 > interjection > with length = 4 1`] = `"geez"`; -exports[`word > 1337 > interjection > with length = 20 1`] = `"ew"`; - -exports[`word > 1337 > interjection > with options.length 1`] = `"ew"`; +exports[`word > 1337 > interjection > with options.length 1`] = `"geez"`; exports[`word > 1337 > interjection > with options.length and options.strategy 1`] = `"gadzooks"`; @@ -262,11 +218,9 @@ exports[`word > 1337 > interjection > with options.strategy 1`] = `"ah"`; exports[`word > 1337 > noun > noArgs 1`] = `"diversity"`; -exports[`word > 1337 > noun > with length = 10 1`] = `"deployment"`; - -exports[`word > 1337 > noun > with length = 20 1`] = `"diversity"`; +exports[`word > 1337 > noun > with length = 4 1`] = `"draw"`; -exports[`word > 1337 > noun > with options.length 1`] = `"deployment"`; +exports[`word > 1337 > noun > with options.length 1`] = `"draw"`; exports[`word > 1337 > noun > with options.length and options.strategy 1`] = `"cross-contamination"`; @@ -274,11 +228,9 @@ exports[`word > 1337 > noun > with options.strategy 1`] = `"CD"`; exports[`word > 1337 > preposition > noArgs 1`] = `"barring"`; -exports[`word > 1337 > preposition > with length = 10 1`] = `"concerning"`; - -exports[`word > 1337 > preposition > with length = 20 1`] = `"barring"`; +exports[`word > 1337 > preposition > with length = 4 1`] = `"into"`; -exports[`word > 1337 > preposition > with options.length 1`] = `"concerning"`; +exports[`word > 1337 > preposition > with options.length 1`] = `"into"`; exports[`word > 1337 > preposition > with options.length and options.strategy 1`] = `"notwithstanding"`; @@ -286,11 +238,9 @@ exports[`word > 1337 > preposition > with options.strategy 1`] = `"a"`; exports[`word > 1337 > sample > noArgs 1`] = `"how"`; -exports[`word > 1337 > sample > with length = 10 1`] = `"how"`; +exports[`word > 1337 > sample > with length = 4 1`] = `"once"`; -exports[`word > 1337 > sample > with length = 20 1`] = `"how"`; - -exports[`word > 1337 > sample > with options.length 1`] = `"how"`; +exports[`word > 1337 > sample > with options.length 1`] = `"once"`; exports[`word > 1337 > sample > with options.length and options.strategy 1`] = `"consequently"`; @@ -298,11 +248,9 @@ exports[`word > 1337 > sample > with options.strategy 1`] = `"if"`; exports[`word > 1337 > verb > noArgs 1`] = `"downshift"`; -exports[`word > 1337 > verb > with length = 10 1`] = `"degenerate"`; - -exports[`word > 1337 > verb > with length = 20 1`] = `"downshift"`; +exports[`word > 1337 > verb > with length = 4 1`] = `"form"`; -exports[`word > 1337 > verb > with options.length 1`] = `"degenerate"`; +exports[`word > 1337 > verb > with options.length 1`] = `"form"`; exports[`word > 1337 > verb > with options.length and options.strategy 1`] = `"institutionalize"`; @@ -310,10 +258,8 @@ exports[`word > 1337 > verb > with options.strategy 1`] = `"gad"`; exports[`word > 1337 > words > noArgs 1`] = `"wallaby"`; -exports[`word > 1337 > words > with count = 10 1`] = `"how yet smooth councilman including safely junior actually accredit vaguely"`; - -exports[`word > 1337 > words > with count = 20 1`] = `"how yet smooth councilman including safely junior actually accredit vaguely failing vaguely mundane hassle whoever scarily requite duh lazily sans"`; +exports[`word > 1337 > words > with count = 4 1`] = `"how yet smooth councilman"`; -exports[`word > 1337 > words > with options.count 1`] = `"how yet smooth councilman including safely junior actually accredit vaguely"`; +exports[`word > 1337 > words > with options.count 1`] = `"how yet smooth councilman"`; exports[`word > 1337 > words > with options.count range 1`] = `"wallaby drat deserted into aggravating yuck vol busily ouch inasmuch haze scientific everlasting or gee harmful phew now"`; diff --git a/test/modules/word.spec.ts b/test/modules/word.spec.ts index 121cce84..646bbc06 100644 --- a/test/modules/word.spec.ts +++ b/test/modules/word.spec.ts @@ -19,9 +19,8 @@ describe('word', () => { 'sample' )((t) => { t.it('noArgs') - .it('with length = 10', 10) - .it('with length = 20', 20) - .it('with options.length', { length: 10 }) + .it('with length = 4', 4) + .it('with options.length', { length: 4 }) .it('with options.strategy', { strategy: 'shortest' }) .it('with options.length and options.strategy', { length: { min: 18, max: 20 }, @@ -31,9 +30,8 @@ describe('word', () => { t.describe('words', (t) => { t.it('noArgs') - .it('with count = 10', 10) - .it('with count = 20', 20) - .it('with options.count', { count: 10 }) + .it('with count = 4', 4) + .it('with options.count', { count: 4 }) .it('with options.count range', { count: { min: 18, max: 20 } }); }); }); @@ -63,13 +61,13 @@ describe('word', () => { expect(result).toEqual(['foo', 'bar', 'baz', 'a']); }); - it('returns the word list if no words match the length', () => { - const result = filterWordListByLength({ - wordList, - length, - }); - // TODO @ST-DDT 2022-10-02: This should throw an error in the next major version. - expect(result).toEqual(wordList); + it('by default throws an error when no words match the given length', () => { + expect(() => { + filterWordListByLength({ + wordList, + length, + }); + }).toThrow('No words found that match the given length.'); }); it('returns the appropriate words when strategy is "any-length" and no words match the given length', () => { |
