Skip to content

Commit c3dc37c

Browse files
added edge cases for isLength test (#2658)
1 parent 784e52a commit c3dc37c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/validators/isLength.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,31 @@ describe('isLength', () => {
141141
valid: ['👩🦰👩👩👦👦🏳️🌈', '⏩︎⏩︎⏪︎⏪︎⏭︎⏭︎⏮︎⏮︎'],
142142
});
143143
});
144+
145+
it('should return true if string exactly match min/max bounds', () => {
146+
test({
147+
validator: 'isLength',
148+
args: [{ min: 3, max: 3 }],
149+
valid: ['abc', 'def'],
150+
invalid: ['abcd', 'efgh'],
151+
});
152+
});
153+
154+
it('should count emojis as single character', () => {
155+
test({
156+
validator: 'isLength',
157+
args: [{ min: 1, max: 1 }],
158+
valid: ['🚀', '🍕', 'A'],
159+
invalid: ['🚀🚀', ''],
160+
});
161+
});
162+
163+
it('should only allow strings with specific lengths from a list', () => {
164+
test({
165+
validator: 'isLength',
166+
args: [{ discreteLengths: [2, 5] }],
167+
valid: ['to', 'hello'],
168+
invalid: ['a', 'cat', 'lengthy'],
169+
});
170+
});
144171
});

0 commit comments

Comments
 (0)