Skip to content

Commit 23866ad

Browse files
authoredMar 31, 2024··
test: add some missing unit tests for 'convertObject' (#5303)
According to AI's suggestions at #5302, it seems there're some missing unit tests and here's the fix for it.
1 parent abd1490 commit 23866ad

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 

‎test/lib/core/utils.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,35 @@ describe('test/lib/core/utils.test.js', () => {
125125
assert(obj.undefined$ === undefined);
126126
assert(obj.boolean$ === '<Boolean>');
127127
assert(obj.symbol$ === '<Symbol>');
128+
assert(obj.regexp$ === '<RegExp>');
129+
});
130+
131+
it('should convert a plain recursive object', () => {
132+
const obj = {
133+
plainObj: 'Plain',
134+
Id: 1,
135+
recurisiveObj: {
136+
value1: 'string',
137+
value2: 1,
138+
ignoreValue: /^[a-z]/,
139+
},
140+
};
141+
utils.convertObject(obj, [ 'ignoreValue' ]);
142+
assert(obj.recurisiveObj.value1 === 'string');
143+
assert(obj.recurisiveObj.value2 === 1);
144+
assert(obj.recurisiveObj.ignoreValue === '<RegExp>');
145+
assert(obj.plainObj === 'Plain');
146+
assert(obj.Id === 1);
147+
});
148+
149+
it('should convert an anonymous class', () => {
150+
const obj = {
151+
anonymousClassWithPropName: class { },
152+
'': class { },
153+
};
154+
utils.convertObject(obj);
155+
assert(obj.anonymousClassWithPropName === '<Class anonymousClassWithPropName>');
156+
assert(obj[''] === '<Class anonymous>');
128157
});
129158
});
130159

0 commit comments

Comments
 (0)
Please sign in to comment.