@ray-core/runtime
Version:
Ray 是一个全新的基于 React 的小程序开发框架
55 lines (54 loc) • 1.67 kB
JavaScript
import propsAlias, { getAlias } from '../propsAlias';
import { RuntimeOptions } from '@ray-core/framework-shared';
describe('props alias', function () {
beforeAll(function () {
RuntimeOptions.apply({
platform: 'ali',
hostComponents: {
foo: {
alias: {
camelCase: 'kebab-case',
},
props: ['kebab-case'],
},
},
});
});
afterAll(function () {
RuntimeOptions.reset();
});
it('transform style prop correctly', function () {
expect(propsAlias({
style: {
color: '#ffffff',
height: '2px',
WebkitFlex: 1,
'--color': 'red',
'--textColor': 'blue',
backgroundColor: 'var(--textColor)',
},
}, 'any')).toMatchSnapshot();
expect(propsAlias({
style: null,
}, 'any')).toMatchSnapshot();
});
it('transform props by component type correctly', function () {
expect(getAlias('prop', 'any')).toBe('prop');
expect(propsAlias({
bar: 'bar',
camelCase: 'value',
}, 'foo')).toEqual({
bar: 'bar',
'kebab-case': 'value',
});
});
it('transform platform props', function () {
expect(getAlias('ali-prop', 'any')).toBe('prop');
});
it('transform platform props priority boost', function () {
expect(propsAlias({
'ali-type': 'foo',
type: 'bar',
}, 'any')).toEqual({ type: 'foo' });
});
});