/** * @jest-environment jsdom * @jsxImportSource ../src */ /* eslint-disable no-lone-blocks */ import { renderJSON, NotHas, Assert, expecter } from '@theme-ui/test-utils' import { matchers } from '@emotion/jest' import { SxProp, ThemeProvider, ThemeUIJSX } from '../src' expect.extend(matchers) describe('JSX', () => { test('accepts sx prop', () => { expect( renderJSON(
console.log(e.target.value)} sx={{ bg: 'primary', }} />
) ).toMatchSnapshot() }) test('sx prop gives a theme that can be read as array or object', () => { const json = renderJSON(
({ boxShadow: t.shadows?.small, '&:hover': { boxShadow: t.shadows?.[2], }, })} /> ) expect(json).toHaveStyleRule('box-shadow', '0 0 4px rgba(0, 0, 0, .125)') }) test('accepts css prop', () => { const expectSnippet = expecter( `/** @jsxImportSource ./packages/core */ export {}`, { jsx: false } ) expectSnippet(`const _1 =
`).toSucceed() // TODO: uncomment this some day // // Theme UI theme can be injected to @emotion/react module in userspace // expectSnippet( // ` // import { Theme as ThemeUITheme } from './packages/css' // declare module '@emotion/react' { // export interface Theme extends ThemeUITheme {} // } //
{ // const _t = t; // return {} // }} // />` // ).toInfer('_t', 'Theme') expectSnippet( `import { css } from '@emotion/react' const TestComponent = () =>
` ).toSucceed() }) }) { type HasSxProp = T extends SxProp ? true : false type DoesNotHaveSxProp = NotHas type _ = | Assert< DoesNotHaveSxProp< ThemeUIJSX.LibraryManagedAttributes< React.FC, { className?: undefined } > >, true > | Assert< | HasSxProp< ThemeUIJSX.LibraryManagedAttributes< React.FC, { className?: string; anotherProp: string; andOneMore: number } > > | HasSxProp< ThemeUIJSX.LibraryManagedAttributes > // if `className` can be whatever, we have `sx` prop | HasSxProp< ThemeUIJSX.LibraryManagedAttributes< React.FC, { className?: unknown } > > // if `className` can be string or many, we have `sx` prop | HasSxProp< ThemeUIJSX.LibraryManagedAttributes< React.FC, { className?: string | string[] } > >, true > }