Skip to content

Commit

Permalink
test: add some missing unit tests for 'convertObject' (#5303)
Browse files Browse the repository at this point in the history
According to AI's suggestions at #5302,
it seems there're some missing unit tests and here's the fix for it.
  • Loading branch information
SEWeiTung authored Mar 31, 2024
1 parent abd1490 commit 23866ad
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/lib/core/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,35 @@ describe('test/lib/core/utils.test.js', () => {
assert(obj.undefined$ === undefined);
assert(obj.boolean$ === '<Boolean>');
assert(obj.symbol$ === '<Symbol>');
assert(obj.regexp$ === '<RegExp>');
});

it('should convert a plain recursive object', () => {
const obj = {
plainObj: 'Plain',
Id: 1,
recurisiveObj: {
value1: 'string',
value2: 1,
ignoreValue: /^[a-z]/,
},
};
utils.convertObject(obj, [ 'ignoreValue' ]);
assert(obj.recurisiveObj.value1 === 'string');
assert(obj.recurisiveObj.value2 === 1);
assert(obj.recurisiveObj.ignoreValue === '<RegExp>');
assert(obj.plainObj === 'Plain');
assert(obj.Id === 1);
});

it('should convert an anonymous class', () => {
const obj = {
anonymousClassWithPropName: class { },
'': class { },
};
utils.convertObject(obj);
assert(obj.anonymousClassWithPropName === '<Class anonymousClassWithPropName>');
assert(obj[''] === '<Class anonymous>');
});
});

Expand Down

0 comments on commit 23866ad

Please sign in to comment.