@@ -415,4 +415,68 @@ describe('cheerio', function () {
415415 expect ( utils . isHtml ( '<123>' ) ) . toBe ( false ) ;
416416 } ) ;
417417 } ) ;
418+
419+ describe ( 'parse5 options' , function ( ) {
420+ var noscript = fixtures . noscript ;
421+
422+ // should parse noscript tags only with false option value
423+ test ( '{scriptingEnabled: ???}' , function ( ) {
424+ var opt = 'scriptingEnabled' ;
425+ var options = { } ;
426+ var result ;
427+
428+ // [default] scriptingEnabled: true - tag contains one text element
429+ result = cheerio . load ( noscript ) ( 'noscript' ) ;
430+ expect ( result ) . toHaveLength ( 1 ) ;
431+ expect ( result [ 0 ] . children ) . toHaveLength ( 1 ) ;
432+ expect ( result [ 0 ] . children [ 0 ] . type ) . toBe ( 'text' ) ;
433+
434+ // scriptingEnabled: false - content of noscript will parsed
435+ options [ opt ] = false ;
436+ result = cheerio . load ( fixtures . noscript , options ) ( 'noscript' ) ;
437+ expect ( result ) . toHaveLength ( 1 ) ;
438+ expect ( result [ 0 ] . children ) . toHaveLength ( 2 ) ;
439+ expect ( result [ 0 ] . children [ 0 ] . type ) . toBe ( 'comment' ) ;
440+ expect ( result [ 0 ] . children [ 1 ] . type ) . toBe ( 'tag' ) ;
441+ expect ( result [ 0 ] . children [ 1 ] . name ) . toBe ( 'a' ) ;
442+
443+ // scriptingEnabled: ??? - should acts as true
444+ var values = [ undefined , null , 0 , '' ] ;
445+ for ( var val of values ) {
446+ options [ opt ] = val ;
447+ result = cheerio . load ( noscript , options ) ( 'noscript' ) ;
448+ expect ( result ) . toHaveLength ( 1 ) ;
449+ expect ( result [ 0 ] . children ) . toHaveLength ( 1 ) ;
450+ expect ( result [ 0 ] . children [ 0 ] . type ) . toBe ( 'text' ) ;
451+ }
452+ } ) ;
453+
454+ // should contain location data only with truthful option value
455+ test ( '{sourceCodeLocationInfo: ???}' , function ( ) {
456+ var prop = 'sourceCodeLocation' ;
457+ var opt = 'sourceCodeLocationInfo' ;
458+ var options = { } ;
459+ var result ;
460+ var i ;
461+
462+ // Location data should not be present
463+ var values = [ undefined , null , 0 , false , '' ] ;
464+ for ( i = 0 ; i < values . length ; i ++ ) {
465+ options [ opt ] = values [ i ] ;
466+ result = cheerio . load ( noscript , options ) ( 'noscript' ) ;
467+ expect ( result ) . toHaveLength ( 1 ) ;
468+ expect ( result [ 0 ] ) . not . toHaveProperty ( prop ) ;
469+ }
470+
471+ // Location data should be present
472+ values = [ true , 1 , 'test' ] ;
473+ for ( i = 0 ; i < values . length ; i ++ ) {
474+ options [ opt ] = values [ i ] ;
475+ result = cheerio . load ( noscript , options ) ( 'noscript' ) ;
476+ expect ( result ) . toHaveLength ( 1 ) ;
477+ expect ( result [ 0 ] ) . toHaveProperty ( prop ) ;
478+ expect ( typeof result [ 0 ] [ prop ] ) . toBe ( 'object' ) ;
479+ }
480+ } ) ;
481+ } ) ;
418482} ) ;
0 commit comments