{
const actual = transform(`
import { ClassNames } from '@compiled/react';
const Component = ({ children }) => (
{({ css, style }) => }
);
`);
expect(actual).toInclude(`style={undefined}`);
});
it('should replace style identifier with css variable object', () => {
const actual = transform(`
import { ClassNames } from '@compiled/react';
const Component = ({ children, color }) => (
{({ css, style }) => }
);
`);
expect(actual).toMatchInlineSnapshot(`
"const _ = "._syaz1aj3{color:var(--_1ylxx6h)}";
const Component = ({ children, color }) => (
{[_]}
{
}
);
"
`);
});
it('should not transform style identifier when its coming from outer scope', () => {
const actual = transform(`
import { ClassNames } from '@compiled/react';
const EmphasisText = ({ className, children, style }) => (
{({ css }) => (
{children}
)}
);
`);
expect(actual).toInclude(`style={style}`);
});
it('should transform style and css renamed prop coming from local variable', () => {
const actual = transform(`
import { ClassNames } from '@compiled/react';
const ListItem = () => (
{(arg) => {
const { css: c, style: styl } = arg;
return (
hello world
);
}}
);
`);
expect(actual).toMatchInlineSnapshot(`
"const _2 = "._syaz5scu{color:red}";
const _ = "._1wyb19bv{font-size:10px}";
const ListItem = () => (
{[_, _2]}
{(() => {
const { css: c, style: styl } = arg;
return (
hello world
);
})()}
);
"
`);
});
it('should apply conditional logical expression object spread styles', () => {
const actual = transform(`
import { ClassNames } from '@compiled/react';
const ListItem = (props) => (
{({ css }) => (hello, world!
)}
);
`);
expect(actual).toInclude('className={ax([props.isPrimary && "_syaz13q2 _1wybgktf"])}');
});
it('should apply array logical-based conditional css', () => {
const actual = transform(
`
import { ClassNames } from '@compiled/react';
const ListItem = (props) => (
{({ css }) => (hello, world!
)}
);
`,
{ pretty: false }
);
expect(actual).toInclude(
'className={ax(["_1wyb1ylp",(props.isPrimary||props.isMaybe)&&"_syaz13q2 _1wybgktf"])}'
);
});
it('should apply array prop ternary-based inline conditional css', () => {
const actual = transform(
`
import { ClassNames } from '@compiled/react';
const ListItem = (props) => (
{({ css }) => (hello, world!
)}
);
`,
{ pretty: false }
);
expect(actual).toInclude(
'className={ax([props.isPrimary?"_bfhk1x77 _syaz11x8":"_bfhkbf54 _syaz5scu","_1wyb1fwx"])}'
);
});
});