fix(variable): should not return undefined when parsing 0 (#2766)

This commit is contained in:
被雨水过滤的空气-Rain 2023-10-09 08:46:46 +08:00 committed by GitHub
parent f5399c2cf0
commit 0d67141a6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 3 deletions

View File

@ -94,4 +94,10 @@ describe('getValuesByPath', () => {
const result = getValuesByPath(arr, 'b', []); const result = getValuesByPath(arr, 'b', []);
expect(result).toEqual([1, 2]); expect(result).toEqual([1, 2]);
}); });
it('should return 0 when the initial value is 0', () => {
const obj = { a: 0 };
const result = getValuesByPath(obj, 'a');
expect(result).toBe(0);
});
}); });

View File

@ -29,7 +29,7 @@ export const getValuesByPath = (obj: object, path: string, defaultValue?: any) =
} }
} }
result = result.filter(Boolean); result = result.filter((item) => item != null);
if (result.length === 0) { if (result.length === 0) {
return defaultValue; return defaultValue;

View File

@ -24,7 +24,7 @@
"module": "commonjs" "module": "commonjs"
} }
}, },
"include": ["packages/**/*", ".dumi/**/*", ".dumirc.ts", "scripts/*", "playwright.config.ts"], "include": ["packages/**/*", ".dumi/**/*", ".dumirc.ts", "scripts/*", "playwright.config.ts", "vitest.config.ts"],
"exclude": [ "exclude": [
"packages/**/node_modules", "packages/**/node_modules",
"packages/**/dist", "packages/**/dist",

View File

@ -34,7 +34,7 @@ export default defineConfig({
{ find: /^~antd\/(.*)/, replacement: 'antd/$1' }, { find: /^~antd\/(.*)/, replacement: 'antd/$1' },
...alias, ...alias,
], ],
include: ['packages/**/{dumi-theme-nocobase,sdk,client}/**/__tests__/**/*.{test,spec}.{ts,tsx}'], include: ['packages/**/{dumi-theme-nocobase,sdk,client,utils}/**/__tests__/**/*.{test,spec}.{ts,tsx}'],
exclude: [ exclude: [
'**/node_modules/**', '**/node_modules/**',
'**/dist/**', '**/dist/**',