diff --git a/packages/tdesign-miniprogram/test/jest.config.js b/packages/tdesign-miniprogram/test/jest.config.js index fb98a8a5d..77cfe42c3 100644 --- a/packages/tdesign-miniprogram/test/jest.config.js +++ b/packages/tdesign-miniprogram/test/jest.config.js @@ -9,8 +9,14 @@ module.exports = { '^tdesign-miniprogram': '/packages/components/index', '^@behaviors/(.*)': '/packages/tdesign-miniprogram/example/behaviors/$1', }, - testMatch: ['/packages/(components|pro-components)/**/__test__/**/*.test.{js,ts}'], - collectCoverageFrom: ['/packages/(components|pro-components)/**/*.{js,ts}', '!**/__test__/**', '!**/_example/**', '!**/type.ts', '!**/props.ts'], + testMatch: ['/packages/(components|pro-components|uniapp-components)/**/__test__/**/*.test.{js,ts}'], + collectCoverageFrom: [ + '/packages/(components|pro-components)/**/*.{js,ts}', + '!**/__test__/**', + '!**/_example/**', + '!**/type.ts', + '!**/props.ts', + ], collectCoverage: true, coverageProvider: 'v8', coverageDirectory: '/packages/tdesign-miniprogram/test/unit/coverage', diff --git a/packages/uniapp-components/common/__test__/instantiationDecorator.test.js b/packages/uniapp-components/common/__test__/instantiationDecorator.test.js new file mode 100644 index 000000000..a2cead74c --- /dev/null +++ b/packages/uniapp-components/common/__test__/instantiationDecorator.test.js @@ -0,0 +1,21 @@ +global.uni = { + getWindowInfo: jest.fn(() => ({})), + getAppBaseInfo: jest.fn(() => ({})), + getDeviceInfo: jest.fn(() => ({})), + getSystemInfoSync: jest.fn(() => ({})), +}; + +const { uniComponent } = require('../src/instantiationDecorator'); +const radioProps = require('../../radio/props').default; +const checkboxProps = require('../../checkbox/props').default; + +describe('uniComponent props', () => { + it.each([ + ['radio', radioProps], + ['checkbox', checkboxProps], + ])('preserves the declared value type order for %s', (_, props) => { + const component = uniComponent({ props: { value: { ...props.value, type: [...props.value.type] } } }); + + expect(component.props.value.type).toEqual([String, Number, Boolean]); + }); +}); diff --git a/packages/uniapp-components/common/src/instantiationDecorator.js b/packages/uniapp-components/common/src/instantiationDecorator.js index be8ac5f12..cebfb1819 100644 --- a/packages/uniapp-components/common/src/instantiationDecorator.js +++ b/packages/uniapp-components/common/src/instantiationDecorator.js @@ -136,22 +136,6 @@ export const wxComponent = function wxComponent() { }; }; -function sortPropsType(type) { - if (!Array.isArray(type)) { - return type; - } - type.sort((a, b) => { - if (a === Boolean) { - return -1; - } - if (b === Boolean) { - return 1; - } - return 0; - }); - return type; -} - function filterProps(props, controlledProps) { const newProps = {}; const emits = []; @@ -188,7 +172,8 @@ function filterProps(props, controlledProps) { } else { newProps[key] = { ...(typeof props[key] === 'object' ? props[key] : {}), - type: sortPropsType(curType), + // Vue uses union prop order to distinguish String and Boolean values. + type: curType, }; } });