@@ -125,6 +125,17 @@ describe('attributeValueToTypedAttributeValue', () => {
125125 unit : 'bytes' ,
126126 } ) ;
127127 } ) ;
128+
129+ it ( 'extracts the value property of an object with a value property' , ( ) => {
130+ // and ignores other properties.
131+ // For now we're fine with this but we may reconsider in the future.
132+ const result = attributeValueToTypedAttributeValue ( { value : 'foo' , unit : 'ms' , bar : 'baz' } ) ;
133+ expect ( result ) . toStrictEqual ( {
134+ value : 'foo' ,
135+ unit : 'ms' ,
136+ type : 'string' ,
137+ } ) ;
138+ } ) ;
128139 } ) ;
129140
130141 describe ( 'unsupported value types' , ( ) => {
@@ -233,22 +244,6 @@ describe('attributeValueToTypedAttributeValue', () => {
233244 type : 'string' ,
234245 } ) ;
235246 } ) ;
236-
237- it ( 'stringifies an attribute-object-like object with additional properties to a string attribute value' , ( ) => {
238- const result = attributeValueToTypedAttributeValue ( { value : 'foo' , bar : 'baz' } ) ;
239- expect ( result ) . toStrictEqual ( {
240- value : '{"value":"foo","bar":"baz"}' ,
241- type : 'string' ,
242- } ) ;
243- } ) ;
244-
245- it ( 'stringifies an attribute-object-like object with a unit property to a string attribute value' , ( ) => {
246- const result = attributeValueToTypedAttributeValue ( { value : 'foo' , unit : 'ms' , bar : 'baz' } ) ;
247- expect ( result ) . toStrictEqual ( {
248- value : '{"value":"foo","unit":"ms","bar":"baz"}' ,
249- type : 'string' ,
250- } ) ;
251- } ) ;
252247 } ) ;
253248
254249 it . each ( [ 1 , true , null , undefined , NaN , Symbol ( 'test' ) , { foo : 'bar' } ] ) (
@@ -275,18 +270,17 @@ describe('isAttributeObject', () => {
275270 expect ( result ) . toBe ( true ) ;
276271 } ) ;
277272
278- it . each ( [
279- 1 ,
280- true ,
281- 'test' ,
282- null ,
283- undefined ,
284- NaN ,
285- Symbol ( 'test' ) ,
286- { value : { foo : 'bar' } , bar : 'baz' } ,
287- { value : 1 , unit : 'ms' , anotherProperty : 'test' } ,
288- ] ) ( 'returns false for an invalid attribute object (%s)' , obj => {
289- const result = isAttributeObject ( obj ) ;
290- expect ( result ) . toBe ( false ) ;
273+ it ( 'returns true for an object with a value property' , ( ) => {
274+ // Explicitly demonstrate this behaviour which for now we're fine with.
275+ // We may reconsider in the future.
276+ expect ( isAttributeObject ( { value : 123.45 , some : 'other property' } ) ) . toBe ( true ) ;
291277 } ) ;
278+
279+ it . each ( [ 1 , true , 'test' , null , undefined , NaN , Symbol ( 'test' ) ] ) (
280+ 'returns false for an invalid attribute object (%s)' ,
281+ obj => {
282+ const result = isAttributeObject ( obj ) ;
283+ expect ( result ) . toBe ( false ) ;
284+ } ,
285+ ) ;
292286} ) ;
0 commit comments