@@ -32,20 +32,24 @@ describe('Audit', function () {
32
32
var mockRules = [ {
33
33
id : 'positive1' ,
34
34
selector : 'input' ,
35
+ tags : [ 'positive' ] ,
35
36
any : [ {
36
37
id : 'positive1-check1' ,
37
38
} ]
38
39
} , {
39
40
id : 'positive2' ,
40
41
selector : '#monkeys' ,
42
+ tags : [ 'positive' ] ,
41
43
any : [ 'positive2-check1' ]
42
44
} , {
43
45
id : 'negative1' ,
44
46
selector : 'div' ,
47
+ tags : [ 'negative' ] ,
45
48
none : [ 'negative1-check1' ]
46
49
} , {
47
50
id : 'positive3' ,
48
51
selector : 'blink' ,
52
+ tags : [ 'positive' ] ,
49
53
any : [ 'positive3-check1' ]
50
54
} ] ;
51
55
@@ -621,14 +625,14 @@ describe('Audit', function () {
621
625
} , isNotCalled ) ;
622
626
} ) ;
623
627
624
- it ( 'should run audit.validateOptions to ensure valid input' , function ( ) {
628
+ it ( 'should run audit.normalizeOptions to ensure valid input' , function ( ) {
625
629
fixture . innerHTML = '<input type="text" aria-label="monkeys">' +
626
630
'<div id="monkeys">bananas</div>' +
627
631
'<input aria-labelledby="monkeys" type="text">' +
628
632
'<blink>FAIL ME</blink>' ;
629
633
var checked = 'options not validated' ;
630
634
631
- a . validateOptions = function ( ) {
635
+ a . normalizeOptions = function ( ) {
632
636
checked = 'options validated' ;
633
637
} ;
634
638
@@ -687,46 +691,127 @@ describe('Audit', function () {
687
691
} ) ;
688
692
} ) ;
689
693
690
- describe ( 'Audit#validateOptions ' , function ( ) {
694
+ describe ( 'Audit#normalizeOptions ' , function ( ) {
691
695
692
696
it ( 'returns the options object when it is valid' , function ( ) {
693
697
var opt = {
694
698
runOnly : {
695
699
type : 'rule' ,
696
- value : [ 'positive1' , 'positive2' ]
700
+ values : [ 'positive1' , 'positive2' ]
697
701
} ,
698
702
rules : {
699
703
negative1 : { enabled : false }
700
704
}
701
705
} ;
702
- assert ( a . validateOptions ( opt ) , opt ) ;
706
+ assert ( a . normalizeOptions ( opt ) , opt ) ;
707
+ } ) ;
708
+
709
+ it ( 'allows `value` as alternative to `values`' , function ( ) {
710
+ var opt = {
711
+ runOnly : {
712
+ type : 'rule' ,
713
+ value : [ 'positive1' , 'positive2' ]
714
+ }
715
+ } ;
716
+ var out = a . normalizeOptions ( opt )
717
+ assert . deepEqual ( out . runOnly . values , [ 'positive1' , 'positive2' ] ) ;
718
+ assert . isUndefined ( out . runOnly . value ) ;
719
+ } ) ;
720
+
721
+ it ( 'allows type: rules as an alternative to type: rule' , function ( ) {
722
+ var opt = {
723
+ runOnly : {
724
+ type : 'rules' ,
725
+ values : [ 'positive1' , 'positive2' ]
726
+ }
727
+ } ;
728
+ assert ( a . normalizeOptions ( opt ) . runOnly . type , 'rule' ) ;
729
+ } ) ;
730
+
731
+ it ( 'allows type: tags as an alternative to type: tag' , function ( ) {
732
+ var opt = {
733
+ runOnly : {
734
+ type : 'tags' ,
735
+ values : [ 'positive' ]
736
+ }
737
+ } ;
738
+ assert ( a . normalizeOptions ( opt ) . runOnly . type , 'tag' ) ;
739
+ } ) ;
740
+
741
+ it ( 'allows type: undefined as an alternative to type: tag' , function ( ) {
742
+ var opt = {
743
+ runOnly : {
744
+ values : [ 'positive' ]
745
+ }
746
+ } ;
747
+ assert ( a . normalizeOptions ( opt ) . runOnly . type , 'tag' ) ;
748
+ } ) ;
749
+
750
+ it ( 'allows runOnly as an array as an alternative to type: tag' , function ( ) {
751
+ var opt = { runOnly : [ 'positive' , 'negative' ] } ;
752
+ var out = a . normalizeOptions ( opt ) ;
753
+ assert ( out . runOnly . type , 'tag' ) ;
754
+ assert . deepEqual ( out . runOnly . values , [ 'positive' , 'negative' ] ) ;
755
+ } ) ;
756
+
757
+ it ( 'throws an error runOnly.values not an array' , function ( ) {
758
+ assert . throws ( function ( ) {
759
+ a . normalizeOptions ( {
760
+ runOnly : {
761
+ type : 'rule' ,
762
+ values : { badProp : 'badValue' }
763
+ }
764
+ } ) ;
765
+ } ) ;
766
+ } ) ;
767
+
768
+ it ( 'throws an error runOnly.values an empty' , function ( ) {
769
+ assert . throws ( function ( ) {
770
+ a . normalizeOptions ( {
771
+ runOnly : {
772
+ type : 'rule' ,
773
+ values : [ ]
774
+ }
775
+ } ) ;
776
+ } ) ;
777
+ } ) ;
778
+
779
+ it ( 'throws an error runOnly.type is unknown' , function ( ) {
780
+ assert . throws ( function ( ) {
781
+ a . normalizeOptions ( {
782
+ runOnly : {
783
+ type : 'something-else' ,
784
+ values : [ 'wcag2aa' ]
785
+ }
786
+ } ) ;
787
+ } ) ;
703
788
} ) ;
704
789
705
790
it ( 'throws an error when option.runOnly has an unknown rule' , function ( ) {
706
791
assert . throws ( function ( ) {
707
- a . validateOptions ( {
792
+ a . normalizeOptions ( {
708
793
runOnly : {
709
794
type : 'rule' ,
710
- value : [ 'frakeRule' ]
795
+ values : [ 'frakeRule' ]
711
796
}
712
797
} ) ;
713
798
} ) ;
714
799
} ) ;
715
800
716
801
it ( 'throws an error when option.runOnly has an unknown tag' , function ( ) {
717
802
assert . throws ( function ( ) {
718
- a . validateOptions ( {
803
+ a . normalizeOptions ( {
719
804
runOnly : {
720
805
type : 'tags' ,
721
- value : [ 'fakeTag' ]
806
+ values : [ 'fakeTag' ]
722
807
}
723
808
} ) ;
724
809
} ) ;
725
810
} ) ;
726
811
727
812
it ( 'throws an error when option.rules has an unknown rule' , function ( ) {
728
813
assert . throws ( function ( ) {
729
- a . validateOptions ( {
814
+ a . normalizeOptions ( {
730
815
rules : {
731
816
fakeRule : { enabled : false }
732
817
}
0 commit comments