Skip to content

Commit 0d8b2db

Browse files
committed
fix tests
1 parent 9105768 commit 0d8b2db

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

packages/core/test/lib/attributes.test.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,21 @@ describe('attributeValueToTypedAttributeValue', () => {
276276
});
277277
});
278278

279-
it.each([undefined, { value: undefined }, { value: undefined, unit: 'byte' }])('ignores %s values', value => {
279+
it.each([undefined, { value: undefined }])('stringifies %s values to ""', value => {
280280
const result = attributeValueToTypedAttributeValue(value, true);
281-
expect(result).toBeUndefined();
281+
expect(result).toEqual({
282+
value: '',
283+
type: 'string',
284+
});
285+
});
286+
287+
it('stringifies undefined values with unit to ""', () => {
288+
const result = attributeValueToTypedAttributeValue({ value: undefined, unit: 'byte' }, true);
289+
expect(result).toEqual({
290+
value: '',
291+
unit: 'byte',
292+
type: 'string',
293+
});
282294
});
283295
});
284296
});
@@ -341,14 +353,33 @@ describe('serializeAttributes', () => {
341353
});
342354
});
343355

344-
it.each([true, false])('ignores undefined values if fallback is %s', fallback => {
356+
it('ignores undefined values if fallback is false', () => {
345357
const result = serializeAttributes(
346358
{ foo: undefined, bar: { value: undefined }, baz: { value: undefined, unit: 'byte' } },
347-
fallback,
359+
false,
348360
);
349361
expect(result).toStrictEqual({});
350362
});
351363

364+
it('stringifies undefined values to "" if fallback is true', () => {
365+
const result = serializeAttributes(
366+
{ foo: undefined, bar: { value: undefined }, baz: { value: undefined, unit: 'byte' } },
367+
true,
368+
);
369+
expect(result).toStrictEqual({
370+
bar: {
371+
type: 'string',
372+
value: '',
373+
},
374+
baz: {
375+
type: 'string',
376+
unit: 'byte',
377+
value: '',
378+
},
379+
foo: { type: 'string', value: '' },
380+
});
381+
});
382+
352383
it('ignores null values by default', () => {
353384
const result = serializeAttributes({ foo: null, bar: { value: null }, baz: { value: null, unit: 'byte' } });
354385
expect(result).toStrictEqual({});

0 commit comments

Comments
 (0)