|
1 | | -import { describe, expect, it, vi } from 'vitest'; |
| 1 | +import { beforeEach, describe, expect, it, vi } from 'vitest'; |
2 | 2 | import { faker } from '../src'; |
| 3 | +import { times } from './support/times'; |
3 | 4 |
|
4 | 5 | describe('random', () => { |
5 | 6 | describe('arrayElement', () => { |
@@ -78,15 +79,72 @@ describe('random', () => { |
78 | 79 | }); |
79 | 80 |
|
80 | 81 | describe('word', () => { |
| 82 | + const bannedChars = [ |
| 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 | + beforeEach(() => { |
| 108 | + faker.locale = 'en'; |
| 109 | + }); |
| 110 | + |
81 | 111 | it('should return a random word', () => { |
82 | 112 | const actual = faker.random.word(); |
83 | 113 |
|
84 | 114 | expect(actual).toBeTruthy(); |
85 | 115 | expect(actual).toBeTypeOf('string'); |
86 | 116 | }); |
| 117 | + |
| 118 | + it.each(times(50))( |
| 119 | + 'should only contain a word without undesirable non-alpha characters (run %i)', |
| 120 | + () => { |
| 121 | + const actual = faker.random.word(); |
| 122 | + |
| 123 | + expect(actual).not.satisfy((word: string) => |
| 124 | + bannedChars.some((char) => word.includes(char)) |
| 125 | + ); |
| 126 | + } |
| 127 | + ); |
| 128 | + |
| 129 | + it.each(times(50))( |
| 130 | + 'should only contain a word without undesirable non-alpha characters, locale=zh_CN (run %i)', |
| 131 | + () => { |
| 132 | + faker.locale = 'zh_CN'; |
| 133 | + |
| 134 | + const actual = faker.random.word(); |
| 135 | + |
| 136 | + expect(actual).not.satisfy((word: string) => |
| 137 | + bannedChars.some((char) => word.includes(char)) |
| 138 | + ); |
| 139 | + } |
| 140 | + ); |
87 | 141 | }); |
88 | 142 |
|
89 | 143 | describe('words', () => { |
| 144 | + beforeEach(() => { |
| 145 | + faker.locale = 'en'; |
| 146 | + }); |
| 147 | + |
90 | 148 | it('should return random words', () => { |
91 | 149 | const actual = faker.random.words(); |
92 | 150 |
|
|
0 commit comments