11/* eslint no-unused-expressions: 0 */
22import "mocha" ;
33import { expect } from "chai" ;
4+ import { strict as assert } from "assert" ;
45import { set } from "../../lib/set" ;
56
67describe ( "pointer.set" , ( ) => {
@@ -13,13 +14,16 @@ describe("pointer.set", () => {
1314 } ) ;
1415
1516 it ( "should create a new object for missing data and object pointer" , ( ) => {
16- const result = set ( null , "/property" , true ) ;
17+ const result = set < Record < string , any > | null > ( null , "/property" , true ) ;
1718
19+ assert ( result ?. property ) ;
1820 expect ( result . property ) . to . be . true ;
1921 } ) ;
2022
2123 it ( "should create a new array for missing data and array property" , ( ) => {
2224 const result = set ( null , "/[]" , true ) ;
25+
26+ assert ( result ) ;
2327 expect ( result [ 0 ] ) . to . be . true ;
2428 } ) ;
2529
@@ -41,6 +45,8 @@ describe("pointer.set", () => {
4145 "/path/to/property" ,
4246 true
4347 ) ;
48+
49+ assert ( result ?. path ?. to ) ;
4450 expect ( result . path . to . property ) . to . be . true ;
4551 } ) ;
4652
@@ -50,60 +56,67 @@ describe("pointer.set", () => {
5056 "/path/to/property" ,
5157 true
5258 ) ;
59+
60+ assert ( result ?. path ?. to ) ;
5361 expect ( result . path . to . property ) . to . be . true ;
5462 expect ( result . path . to . id ) . to . eq ( "parent" ) ;
5563 } ) ;
5664
5765 it ( "should insert array for []" , ( ) => {
58- const result = set < { array ?: Array < any > } > ( { } , "/array/[]" , true ) ;
66+ const result = set < { array ?: any [ ] } > ( { } , "/array/[]" , true ) ;
5967
68+ assert ( result ?. array ) ;
6069 expect ( result . array ) . to . be . an ( "array" ) ;
6170 expect ( result . array . length ) . to . eq ( 1 ) ;
6271 } ) ;
6372
6473 it ( "should insert index in array" , ( ) => {
65- const result = set < { array ?: Array < any > } > ( { } , "/array/[1]" , true ) ;
74+ const result = set < { array ?: any [ ] } > ( { } , "/array/[1]" , true ) ;
6675
76+ assert ( result . array ) ;
6777 expect ( result . array ) . to . be . an ( "array" ) ;
6878 expect ( result . array . length ) . to . eq ( 2 ) ;
6979 expect ( result . array [ 1 ] ) . to . be . true ;
7080 } ) ;
7181
7282 it ( "should append item to array" , ( ) => {
73- const result = set < { array ?: Array < any > } > ( { array : [ "first" ] } , "/array/[]" , "next" ) ;
83+ const result = set < { array : any [ ] } > ( { array : [ "first" ] } , "/array/[]" , "next" ) ;
7484
7585 expect ( result . array ) . to . be . an ( "array" ) ;
7686 expect ( result . array ) . to . deep . equal ( [ "first" , "next" ] )
7787 } ) ;
7888
7989 it ( "should insert array in array" , ( ) => {
80- const result = set < { array ?: Array < any > } > ( { } , "/array/[]/[]" , true ) ;
90+ const result = set < { array ?: any [ ] } > ( { } , "/array/[]/[]" , true ) ;
8191
92+ assert ( result . array ) ;
8293 expect ( result . array ) . to . be . an ( "array" ) ;
8394 expect ( result . array [ 0 ] [ 0 ] ) . to . be . true ;
8495 } ) ;
8596
8697 it ( "should insert array to index in array" , ( ) => {
87- const result = set < { array ?: Array < any > } > ( { } , "/array/[1]/[]" , true ) ;
98+ const result = set < { array ?: any [ ] } > ( { } , "/array/[1]/[]" , true ) ;
8899
100+ assert ( result . array ) ;
89101 expect ( result . array ) . to . be . an ( "array" ) ;
90102 expect ( result . array [ 1 ] [ 0 ] ) . to . be . true ;
91103 } ) ;
92104
93105 it ( "should insert object in array" , ( ) => {
94- const result = set < { array ?: Array < any > } > (
106+ const result = set < { array ?: any [ ] } > (
95107 { } ,
96108 "/array/[1]/valid" ,
97109 true
98110 ) ;
99111
112+ assert ( result . array ) ;
100113 expect ( result . array . length ) . to . eq ( 2 ) ;
101114 expect ( result . array [ 1 ] ) . to . be . an ( "object" ) ;
102115 expect ( result . array [ 1 ] . valid ) . to . be . true ;
103116 } ) ;
104117
105118 it ( "should add property to object in array" , ( ) => {
106- const result = set < { array ?: Array < any > } > (
119+ const result = set < { array : any [ ] } > (
107120 { array : [ "first" , { id : 123 } ] } ,
108121 "/array/[1]/valid" ,
109122 true
@@ -115,7 +128,7 @@ describe("pointer.set", () => {
115128 } ) ;
116129
117130 it ( "should append object in array" , ( ) => {
118- const result = set < { array ?: Array < any > } > (
131+ const result = set < { array : any [ ] } > (
119132 { array : [ "first" , { id : 123 } ] } ,
120133 "/array/[]/valid" ,
121134 true
@@ -128,12 +141,13 @@ describe("pointer.set", () => {
128141 } ) ;
129142
130143 it ( "should accept a list of properties as pointer" , ( ) => {
131- const result = set < { array ?: Array < any > } > (
144+ const result = set < { array ?: any [ ] } > (
132145 { } ,
133146 [ "array" , "[1]" , "valid" ] ,
134147 true
135148 ) ;
136149
150+ assert ( result . array ) ;
137151 expect ( result . array . length ) . to . eq ( 2 ) ;
138152 expect ( result . array [ 1 ] ) . to . be . an ( "object" ) ;
139153 expect ( result . array [ 1 ] . valid ) . to . be . true ;
@@ -147,15 +161,18 @@ describe("pointer.set", () => {
147161 true
148162 ) ;
149163
164+ assert ( result . path ?. to ) ;
150165 expect ( result . path . to . property ) . to . be . true ;
151166 } ) ;
152167
153168 it ( "should insert object in array" , ( ) => {
154- const result = set < { array ?: Array < any > } > (
169+ const result = set < { array ?: any [ ] } > (
155170 { } ,
156171 "#/array/[1]/valid" ,
157172 true
158173 ) ;
174+
175+ assert ( result . array ) ;
159176 expect ( result . array . length ) . to . eq ( 2 ) ;
160177 expect ( result . array [ 1 ] ) . to . be . an ( "object" ) ;
161178 expect ( result . array [ 1 ] . valid ) . to . be . true ;
0 commit comments