1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
import validator from 'validator';
import { describe, expect, it } from 'vitest';
import { faker } from '../src';
import { seededTests } from './support/seededRuns';
import { times } from './support/times';
const NON_SEEDED_BASED_RUN = 5;
describe('lorem', () => {
seededTests(faker, 'lorem', (t) => {
t.describe('word', (t) => {
t.it('noArgs')
.it('with length', 10)
.it('with options.length', { length: 10 })
.it('with options.strategy', { strategy: 'shortest' })
.it('with options.length and options.strategy', {
length: { min: 18, max: 20 },
strategy: 'closest',
});
});
t.describeEach(
'words',
'sentence',
'slug',
'sentences',
'paragraph',
'paragraphs',
'text',
'lines'
)((t) => {
t.it('noArgs')
.it('with length', 10)
.it('with length range', { min: 10, max: 20 });
});
});
describe(`random seeded tests for seed ${faker.seed()}`, () => {
for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) {
describe('word()', () => {
it('should return random value from word array', () => {
const actual = faker.lorem.word();
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(faker.definitions.lorem.words).toContain(actual);
});
// INFO @Shinigami92 2022-02-11: Seems there are only words with a max length of 14 characters
it.each(times(14))(
'should return random value from word array with a max length of %i characters',
(length) => {
const actual = faker.lorem.word(length);
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(faker.definitions.lorem.words).toContain(actual);
expect(actual).toHaveLength(length);
}
);
});
describe('words()', () => {
it('should return three random values from words array', () => {
const actual = faker.lorem.words();
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
const words = actual.split(' ');
expect(words).toHaveLength(3);
for (const word of words) {
expect(faker.definitions.lorem.words).toContain(word);
}
});
it.each(times(25))(
'should return %i random values from words array',
(num) => {
const actual = faker.lorem.words(num);
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
const words = actual.split(' ');
expect(words).toHaveLength(num);
for (const word of words) {
expect(faker.definitions.lorem.words).toContain(word);
}
}
);
it('should return a random amount of words', () => {
const actual = faker.lorem.words({ min: 10, max: 20 });
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
const words = actual.split(' ');
expect(words.length).toBeGreaterThanOrEqual(10);
expect(words.length).toBeLessThanOrEqual(20);
for (const word of words) {
expect(faker.definitions.lorem.words).toContain(word);
}
});
});
describe('sentence()', () => {
it('should return a sentence', () => {
const actual = faker.lorem.sentence();
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual[actual.length - 1]).toBe('.');
});
it.each(times(25))(
'should return a sentence with %i words',
(wordCount) => {
const actual = faker.lorem.sentence(wordCount);
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual[actual.length - 1]).toBe('.');
const words = actual.split(' ');
expect(words).toHaveLength(wordCount);
}
);
it('should return a sentence with a random amount of words', () => {
const actual = faker.lorem.sentence({ min: 10, max: 20 });
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
const words = actual.split(' ');
expect(words.length).toBeGreaterThanOrEqual(10);
expect(words.length).toBeLessThanOrEqual(20);
});
});
describe('slug()', () => {
it('should return a slug', () => {
const actual = faker.lorem.slug();
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual).toSatisfy(validator.isSlug);
});
it.each(times(25))(
'should return a slug combined from %i words',
(wordCount) => {
const actual = faker.lorem.slug(wordCount);
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
const words = actual.split('-');
expect(words).toHaveLength(wordCount);
if (wordCount > 1) {
expect(actual).toSatisfy(validator.isSlug);
}
}
);
});
describe('sentences()', () => {
it('should return sentences', () => {
const actual = faker.lorem.sentences();
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual[actual.length - 1]).toBe('.');
});
it.each(times(10))('should return %i sentences', (sentenceCount) => {
const actual = faker.lorem.sentences(sentenceCount);
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual[actual.length - 1]).toBe('.');
const sentences = actual.split('. ');
expect(sentences).toHaveLength(sentenceCount);
});
it.each(times(10))(
'should return %i sentences separated by \\n',
(sentenceCount) => {
const separator = '\n';
const actual = faker.lorem.sentences(sentenceCount, separator);
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual[actual.length - 1]).toBe('.');
const sentences = actual.split(separator);
expect(sentences).toHaveLength(sentenceCount);
for (const sentence of sentences) {
expect(sentence[sentence.length - 1]).toBe('.');
}
}
);
it('should return a random amount of sentences', () => {
const actual = faker.lorem.sentences({ min: 10, max: 20 });
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
const sentences = actual.split('. ');
expect(sentences.length).toBeGreaterThanOrEqual(10);
expect(sentences.length).toBeLessThanOrEqual(20);
});
});
describe('paragraph()', () => {
it('should return a paragraph', () => {
const actual = faker.lorem.paragraph();
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual[actual.length - 1]).toBe('.');
});
it.each(times(10))(
'should return a paragraph with %i sentences',
(sentenceCount) => {
const actual = faker.lorem.paragraph(sentenceCount);
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual[actual.length - 1]).toBe('.');
const sentences = actual.split('. ');
expect(sentences.length).toBeGreaterThanOrEqual(sentenceCount);
expect(sentences.length).toBeLessThanOrEqual(sentenceCount + 3);
}
);
it('should return a paragraph with a random amount of sentences', () => {
const actual = faker.lorem.paragraph({ min: 10, max: 20 });
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
const sentences = actual.split('. ');
expect(sentences.length).toBeGreaterThanOrEqual(10);
expect(sentences.length).toBeLessThanOrEqual(20);
});
});
describe('paragraphs()', () => {
it('should return paragraphs', () => {
const actual = faker.lorem.paragraphs();
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual[actual.length - 1]).toBe('.');
});
it.each(times(5))('should return %i paragraphs', (paragraphCount) => {
const actual = faker.lorem.paragraphs(paragraphCount);
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual[actual.length - 1]).toBe('.');
const paragraphs = actual.split('\n');
expect(paragraphs).toHaveLength(paragraphCount);
});
it.each(times(5))(
'should return %i paragraphs separated by \\n\\n',
(paragraphCount) => {
const separator = '\n\n';
const actual = faker.lorem.paragraphs(paragraphCount, separator);
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
expect(actual[actual.length - 1]).toBe('.');
const paragraphs = actual.split(separator);
expect(paragraphs).toHaveLength(paragraphCount);
}
);
it('should return a random amount of paragraphs', () => {
const actual = faker.lorem.paragraphs({ min: 10, max: 20 });
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
const paragraphs = actual.split('\n');
expect(paragraphs.length).toBeGreaterThanOrEqual(10);
expect(paragraphs.length).toBeLessThanOrEqual(20);
});
});
describe('text()', () => {
it('should return text', () => {
const actual = faker.lorem.text();
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
});
});
describe('lines()', () => {
it('should return lines', () => {
const actual = faker.lorem.lines();
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
});
it.each(times(25))('should return %i lines', (lineCount) => {
const actual = faker.lorem.lines(lineCount);
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
const lines = actual.split('\n');
expect(lines).toHaveLength(lineCount);
});
it('should return a random amount of lines', () => {
const actual = faker.lorem.lines({ min: 10, max: 20 });
expect(actual).toBeTruthy();
expect(actual).toBeTypeOf('string');
const lines = actual.split('\n');
expect(lines.length).toBeGreaterThanOrEqual(10);
expect(lines.length).toBeLessThanOrEqual(20);
});
});
}
});
});
|