Testing invalid character ranges

20 views
Skip to first unread message

Adam Boxall

unread,
Nov 19, 2015, 3:01:49 PM11/19/15
to nodejs
HI

I'm writing unit tests for the validation of a registration form. Most of the fields are quite straight-forward, but I'm a little unsure about invalid usernames. I need to restrict the value to 4-32 characters of a-z, 0-9, "." and "_". Testing valid data is quite straight-forward, it's the huge number of invalid possibilities that has me stumped.

If possible I want to avoid a large and very manual list of test data; the ideal would be for a module to generate that list for me according to certain specifications. Unfortunately I can't seem to find such a module.

Why do other people do in these situations?

Thanks

Aria Stewart

unread,
Nov 19, 2015, 3:04:37 PM11/19/15
to nodejs
I do something like if (!/^[a-z0-9._]{4,32}$/.test(username)) throw new Error("username is not valid) 
Reply all
Reply to author
Forward
0 new messages