@@ -742,132 +742,100 @@ test('children', async function (t) {
742
742
}
743
743
)
744
744
745
- await t . test (
746
- 'should allow omitting `properties` for a `string`' ,
747
- async function ( ) {
748
- assert . deepEqual ( h ( 'strong' , 'foo' ) , {
749
- type : 'element' ,
750
- tagName : 'strong' ,
751
- properties : { } ,
752
- children : [ { type : 'text' , value : 'foo' } ]
753
- } )
754
- }
755
- )
756
-
757
- await t . test (
758
- 'should allow omitting `properties` for a node' ,
759
- async function ( ) {
760
- assert . deepEqual ( h ( 'strong' , h ( 'span' , 'foo' ) ) , {
761
- type : 'element' ,
762
- tagName : 'strong' ,
763
- properties : { } ,
764
- children : [
765
- {
766
- type : 'element' ,
767
- tagName : 'span' ,
768
- properties : { } ,
769
- children : [ { type : 'text' , value : 'foo' } ]
770
- }
771
- ]
772
- } )
773
- }
774
- )
775
-
776
- await t . test (
777
- 'should allow omitting `properties` for an array' ,
778
- async function ( ) {
779
- assert . deepEqual ( h ( 'strong' , [ 'foo' , 'bar' ] ) , {
780
- type : 'element' ,
781
- tagName : 'strong' ,
782
- properties : { } ,
783
- children : [
784
- { type : 'text' , value : 'foo' } ,
785
- { type : 'text' , value : 'bar' }
786
- ]
787
- } )
788
- }
789
- )
790
-
791
- await t . test (
792
- 'should *not* allow omitting `properties` for an `input[type=text][value]`, as those are void and clash' ,
793
- async function ( ) {
794
- assert . deepEqual ( h ( 'input' , { type : 'text' , value : 'foo' } ) , {
795
- type : 'element' ,
796
- tagName : 'input' ,
797
- properties : { type : 'text' , value : 'foo' } ,
798
- children : [ ]
799
- } )
800
- }
801
- )
745
+ await t . test ( 'should disambiguate non-object as a child' , async function ( ) {
746
+ assert . deepEqual ( h ( 'x' , 'y' ) , {
747
+ type : 'element' ,
748
+ tagName : 'x' ,
749
+ properties : { } ,
750
+ children : [ { type : 'text' , value : 'y' } ]
751
+ } )
752
+ } )
802
753
803
- await t . test (
804
- 'should *not* allow omitting `properties` for a `[type]`, without `value` or `children`' ,
805
- async function ( ) {
806
- assert . deepEqual ( h ( 'a' , { type : 'text/html' } ) , {
807
- type : 'element' ,
808
- tagName : 'a' ,
809
- properties : { type : 'text/html' } ,
810
- children : [ ]
811
- } )
812
- }
813
- )
754
+ await t . test ( 'should disambiguate `array` as a child' , async function ( ) {
755
+ assert . deepEqual ( h ( 'x' , [ 'y' ] ) , {
756
+ type : 'element' ,
757
+ tagName : 'x' ,
758
+ properties : { } ,
759
+ children : [ { type : 'text' , value : 'y' } ]
760
+ } )
761
+ } )
814
762
815
763
await t . test (
816
- 'should * not* allow omitting `properties` when `children` is not set to an array ' ,
764
+ 'should not disambiguate an object w/o `type` as a child ' ,
817
765
async function ( ) {
818
- assert . deepEqual ( h ( 'foo' , { type : 'text/html' , children : { bar : 'baz' } } ) , {
819
- type : 'element' ,
820
- tagName : 'foo' ,
821
- properties : { type : 'text/html' , children : '[object Object]' } ,
822
- children : [ ]
823
- } )
766
+ assert . deepEqual (
767
+ // @ts -expect-error: incorrect properties.
768
+ h ( 'x' , {
769
+ a : 'y' ,
770
+ b : 1 ,
771
+ c : true ,
772
+ d : [ 'z' ] ,
773
+ e : { f : true }
774
+ } ) ,
775
+ {
776
+ type : 'element' ,
777
+ tagName : 'x' ,
778
+ properties : {
779
+ a : 'y' ,
780
+ b : 1 ,
781
+ c : true ,
782
+ d : [ 'z' ] ,
783
+ e : '[object Object]'
784
+ } ,
785
+ children : [ ]
786
+ }
787
+ )
824
788
}
825
789
)
826
790
827
791
await t . test (
828
- 'should *not* allow omitting `properties` when a button has a valid type ' ,
792
+ 'should disambiguate an object w/ a `type` and an array of non-primitives as a child ' ,
829
793
async function ( ) {
830
- assert . deepEqual ( h ( 'button' , { type : 'submit' , value : 'Send' } ) , {
831
- type : 'element' ,
832
- tagName : 'button' ,
833
- properties : { type : 'submit' , value : 'Send' } ,
834
- children : [ ]
835
- } )
794
+ assert . deepEqual (
795
+ // @ts -expect-error: unknown node.
796
+ h ( 'x' , { type : 'y' , key : [ { value : 1 } ] } ) ,
797
+ {
798
+ type : 'element' ,
799
+ tagName : 'x' ,
800
+ properties : { } ,
801
+ children : [ { type : 'y' , key : [ { value : 1 } ] } ]
802
+ }
803
+ )
836
804
}
837
805
)
838
806
839
807
await t . test (
840
- 'should * not* allow omitting `properties` when a button has a valid non-lowercase type ' ,
808
+ 'should not disambiguate an object w/ a `type` and an array of primitives as a child ' ,
841
809
async function ( ) {
842
- assert . deepEqual ( h ( 'button ' , { type : 'BUTTON ' , value : 'Send' } ) , {
810
+ assert . deepEqual ( h ( 'x ' , { type : 'y ' , key : [ 1 ] } ) , {
843
811
type : 'element' ,
844
- tagName : 'button ' ,
845
- properties : { type : 'BUTTON ' , value : 'Send' } ,
812
+ tagName : 'x ' ,
813
+ properties : { type : 'y ' , key : [ 1 ] } ,
846
814
children : [ ]
847
815
} )
848
816
}
849
817
)
850
818
851
819
await t . test (
852
- 'should *not* allow omitting `properties` when a button has a valid type ' ,
820
+ 'should disambiguate an object w/ a `type` and an `object` as a child ' ,
853
821
async function ( ) {
854
- assert . deepEqual ( h ( 'button ' , { type : 'menu ' , value : 'Send' } ) , {
822
+ assert . deepEqual ( h ( 'x ' , { type : 'y ' , data : { bar : 'baz' } } ) , {
855
823
type : 'element' ,
856
- tagName : 'button ' ,
857
- properties : { type : 'menu' , value : 'Send' } ,
858
- children : [ ]
824
+ tagName : 'x ' ,
825
+ properties : { } ,
826
+ children : [ { type : 'y' , data : { bar : 'baz' } } ]
859
827
} )
860
828
}
861
829
)
862
830
863
831
await t . test (
864
- 'should allow omitting `properties` when a button has an invalid type ' ,
832
+ 'should disambiguate an object w/ a `type` and an empty `children` array is a child ' ,
865
833
async function ( ) {
866
- assert . deepEqual ( h ( 'button ' , { type : 'text ' , value : 'Send' } ) , {
834
+ assert . deepEqual ( h ( 'x ' , { type : 'y ' , children : [ ] } ) , {
867
835
type : 'element' ,
868
- tagName : 'button ' ,
836
+ tagName : 'x ' ,
869
837
properties : { } ,
870
- children : [ { type : 'text ' , value : 'Send' } ]
838
+ children : [ { type : 'y ' , children : [ ] } ]
871
839
} )
872
840
}
873
841
)
0 commit comments