@@ -16,6 +16,7 @@ describe('validation library', function() {
1616 it ( 'multiple dots' , function ( ) { assert . equal ( true , lib . email ( '[email protected] ' ) ) ; } ) ; 1717 it ( 'multiple @s' , function ( ) { assert . equal ( true , lib . email ( 'a@[email protected] ' ) ) ; } ) ; 1818 it ( 'numbers' , function ( ) { assert . equal ( true , lib . email ( '[email protected] ' ) ) ; } ) ; 19+ it ( 'null' , function ( ) { assert . equal ( false , lib . email ( null ) ) ; } ) ;
1920 } ) ;
2021 describe ( 'equals' , function ( ) {
2122 it ( 'value' , function ( ) { assert . equal ( true , lib . equals ( '3' , '3' ) ) ; } ) ;
@@ -150,6 +151,28 @@ describe('validation library', function() {
150151 it ( '{}' , function ( ) { assert . equal ( false , lib . required ( { } ) ) ; } ) ;
151152 it ( 'boolean true' , function ( ) { assert . equal ( false , lib . required ( { } ) ) ; } ) ;
152153 } ) ;
154+ describe ( 'startsWith' , function ( ) {
155+ it ( 'normal case' , function ( ) { assert . equal ( true , lib . startsWith ( 'kilgore trout' , 'kilg' ) ) ; } ) ;
156+ it ( 'no match' , function ( ) { assert . equal ( false , lib . startsWith ( 'kilgore trout' , 'a' ) ) ; } ) ;
157+ it ( 'spaces' , function ( ) { assert . equal ( true , lib . startsWith ( 'kilgore trout' , 'kilgore ' ) ) ; } ) ;
158+ it ( 'null' , function ( ) { assert . equal ( false , lib . startsWith ( null ) ) ; } ) ;
159+ it ( 'null searchString' , function ( ) { assert . equal ( false , lib . startsWith ( 'kilgore trout' , null ) ) ; } ) ;
160+ it ( 'non-string searchString' , function ( ) { assert . equal ( false , lib . startsWith ( 'kilgore trout' , 3 ) ) ; } ) ;
161+ it ( 'trims value' , function ( ) { assert . equal ( true , lib . startsWith ( ' kilgore trout' , 'kilg' ) ) ; } ) ;
162+ it ( 'does not trim searchString' , function ( ) { assert . equal ( false , lib . startsWith ( 'kilgore trout' , ' kilg' ) ) ; } ) ;
163+ it ( 'does not trim searchString2' , function ( ) { assert . equal ( false , lib . startsWith ( ' kilgore trout' , ' kilg' ) ) ; } ) ;
164+ it ( 'empty string' , function ( ) { assert . equal ( false , lib . startsWith ( '' , 'kilgore ' ) ) ; } ) ;
165+ } ) ;
166+ describe ( 'url' , function ( ) {
167+ it ( 'matches http' , function ( ) { assert . equal ( true , lib . url ( 'http://react-formstate-validation.test' ) ) ; } ) ;
168+ it ( 'matches https' , function ( ) { assert . equal ( true , lib . url ( 'https://react-formstate-validation.test' ) ) ; } ) ;
169+ it ( 'matches ftp' , function ( ) { assert . equal ( true , lib . url ( 'ftp://react-formstate-validation.test' ) ) ; } ) ;
170+ it ( 'does not match relative' , function ( ) { assert . equal ( false , lib . url ( '/react-formstate-validation.test' ) ) ; } ) ;
171+ it ( 'does not match schema relative' , function ( ) { assert . equal ( false , lib . url ( '//react-formstate-validation.test' ) ) ; } ) ;
172+ it ( 'does not match site relative' , function ( ) { assert . equal ( false , lib . url ( '~/react-formstate-validation.test' ) ) ; } ) ;
173+ it ( 'does not match gopher' , function ( ) { assert . equal ( false , lib . url ( 'gopher://react-formstate-validation.test' ) ) ; } ) ;
174+ it ( 'does not crash' , function ( ) { assert . equal ( false , lib . url ( null ) ) ; } ) ;
175+ } ) ;
153176} ) ;
154177
155178function mock ( validations ) {
@@ -304,6 +327,22 @@ describe('Messages', function() {
304327 assert . equal ( undefined , v [ 'required' ] ( '46' , 'Field' ) ) ;
305328 } ) ;
306329 } ) ;
330+ describe ( '#startsWith' , function ( ) {
331+ it ( 'has a message' , function ( ) {
332+ assert . equal ( 'Field must start with f' , v [ 'startsWith' ] ( '' , 'Field' , 'f' ) ) ;
333+ } ) ;
334+ it ( 'might not return a message' , function ( ) {
335+ assert . equal ( undefined , v [ 'startsWith' ] ( 'f' , 'Field' , 'f' ) ) ;
336+ } ) ;
337+ } ) ;
338+ describe ( '#url' , function ( ) {
339+ it ( 'has a message' , function ( ) {
340+ assert . equal ( 'Field must be a url' , v [ 'url' ] ( '' , 'Field' ) ) ;
341+ } ) ;
342+ it ( 'might not return a message' , function ( ) {
343+ assert . equal ( undefined , v [ 'url' ] ( 'http://test.test' , 'Field' ) ) ;
344+ } ) ;
345+ } ) ;
307346} ) ;
308347
309348
0 commit comments