1+ const { parseScope } = require ( '../../../lib/utils/scope-util' ) ;
2+ const should = require ( 'chai' ) . should ( ) ;
3+
4+ describe ( parseScope . name , ( ) => {
5+ it ( 'should return undefined on nullish values' , ( ) => {
6+ const values = [ undefined , null ] ;
7+ values . forEach ( str => {
8+ const compare = parseScope ( str ) === undefined ;
9+ compare . should . equal ( true ) ;
10+ } ) ;
11+ } ) ;
12+ it ( 'should throw on non-string values' , ( ) => {
13+ const invalid = [ 1 , - 1 , true , false , { } , [ 'foo' ] , [ ] , ( ) => { } , Symbol ( 'foo' ) ] ;
14+ invalid . forEach ( str => {
15+ try {
16+ parseScope ( str ) ;
17+ should . fail ( ) ;
18+ } catch ( e ) {
19+ e . message . should . eql ( 'Invalid parameter: `scope`' ) ;
20+ }
21+ } ) ;
22+ } ) ;
23+ it ( 'should throw on empty strings' , ( ) => {
24+ const invalid = [ '' , ' ' , ' ' , '\n' , '\t' , '\r' ] ;
25+ invalid . forEach ( str => {
26+ try {
27+ parseScope ( str ) ;
28+ should . fail ( ) ;
29+ } catch ( e ) {
30+ e . message . should . eql ( 'Invalid parameter: `scope`' ) ;
31+ }
32+ } ) ;
33+ } ) ;
34+ it ( 'should split space-delimited strings into arrays' , ( ) => {
35+ const values = [
36+ [ 'foo' , [ 'foo' ] ] ,
37+ [ 'foo bar' , [ 'foo' , 'bar' ] ] ,
38+ [ 'foo bar' , [ 'foo' , 'bar' ] ] ,
39+ ] ;
40+ values . forEach ( ( [ str , compare ] ) => {
41+ const parsed = parseScope ( str ) ;
42+ parsed . should . deep . equal ( compare ) ;
43+ } ) ;
44+ } ) ;
45+ } ) ;
0 commit comments