From 23866adff50db2946abefcbaa9e2901cd51f4bf8 Mon Sep 17 00:00:00 2001 From: "Wai.Dung" Date: Sun, 31 Mar 2024 17:08:52 +0800 Subject: [PATCH] test: add some missing unit tests for 'convertObject' (#5303) According to AI's suggestions at https://github.com/eggjs/egg/pull/5302, it seems there're some missing unit tests and here's the fix for it. --- test/lib/core/utils.test.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/lib/core/utils.test.js b/test/lib/core/utils.test.js index 623e9c2697..35683ab8f6 100644 --- a/test/lib/core/utils.test.js +++ b/test/lib/core/utils.test.js @@ -125,6 +125,35 @@ describe('test/lib/core/utils.test.js', () => { assert(obj.undefined$ === undefined); assert(obj.boolean$ === ''); assert(obj.symbol$ === ''); + assert(obj.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 === ''); + 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 === ''); + assert(obj[''] === ''); }); });