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', []);
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) {
return defaultValue;

View File

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

View File

@ -34,7 +34,7 @@ export default defineConfig({
{ find: /^~antd\/(.*)/, replacement: 'antd/$1' },
...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: [
'**/node_modules/**',
'**/dist/**',