Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/tdesign-miniprogram/test/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ module.exports = {
'^tdesign-miniprogram': '<rootDir>/packages/components/index',
'^@behaviors/(.*)': '<rootDir>/packages/tdesign-miniprogram/example/behaviors/$1',
},
testMatch: ['<rootDir>/packages/(components|pro-components)/**/__test__/**/*.test.{js,ts}'],
collectCoverageFrom: ['<rootDir>/packages/(components|pro-components)/**/*.{js,ts}', '!**/__test__/**', '!**/_example/**', '!**/type.ts', '!**/props.ts'],
testMatch: ['<rootDir>/packages/(components|pro-components|uniapp-components)/**/__test__/**/*.test.{js,ts}'],
collectCoverageFrom: [
'<rootDir>/packages/(components|pro-components)/**/*.{js,ts}',
'!**/__test__/**',
'!**/_example/**',
'!**/type.ts',
'!**/props.ts',
],
collectCoverage: true,
coverageProvider: 'v8',
coverageDirectory: '<rootDir>/packages/tdesign-miniprogram/test/unit/coverage',
Expand Down
Original file line number Diff line number Diff line change
@@ -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]);
});
});
19 changes: 2 additions & 17 deletions packages/uniapp-components/common/src/instantiationDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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,
};
}
});
Expand Down