/**
* @jest-environment node
*/
// eslint-disable-next-line import/no-extraneous-dependencies
import { styled } from '@compiled/react';
// eslint-disable-next-line import/no-extraneous-dependencies
import { CC as CompiledRoot } from '@compiled/react/runtime';
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
describe('SSR', () => {
it('should render styles inline', () => {
const StyledDiv = styled.div`
font-size: 12px;
`;
const result = renderToStaticMarkup(hello world);
expect(result).toMatchInlineSnapshot(
`"
hello world
"`
);
});
it('should not render undefined into the output HTML when the interpolation is undefined', () => {
const Interpolation = styled.div<{ fontSize?: number }>`
font-size: ${(props) => props.fontSize}px;
`;
const result = renderToStaticMarkup(hello world);
expect(result).not.toContain('undefined');
});
it('should only render one style block when wrapped in a compiled component when siblings', () => {
const StyledDiv = styled.div`
font-size: 12px;
`;
const result = renderToStaticMarkup(
hello world
hello world
);
expect(result).toMatchInlineSnapshot(
`"hello world
hello world
"`
);
});
it('should render semantically higher in the tree so FOUC does not occur when wrapped in compiled component', () => {
const StyledDiv = styled.div`
font-size: 12px;
`;
const result = renderToStaticMarkup(
);
expect(result).toMatchInlineSnapshot(
`""`
);
});
it('should only render one style element when having a parent compiled component', () => {
const StyledParent = styled.div`
display: flex;
`;
const StyledDiv = styled.div`
font-size: 12px;
`;
const result = renderToStaticMarkup(
hello world
hello world
);
expect(result).toMatchInlineSnapshot(
`""`
);
});
it('should render style tags in buckets', () => {
const StyledLink = styled.a`
display: flex;
font-size: 50px;
color: purple;
:hover {
color: yellow;
}
:active {
color: blue;
}
:link {
color: red;
}
@supports (display: grid) {
:active {
color: black;
}
:focus {
color: yellow;
}
}
:focus {
color: green;
}
:visited {
color: pink;
}
@media (max-width: 800px) {
:active {
color: black;
}
:focus {
color: yellow;
}
}
`;
const result = renderToStaticMarkup(
Atlassian Design System
);
expect(result.split('').join('\n')).toMatchInlineSnapshot(`
"
Atlassian Design System"
`);
});
it('should not render escaped HTML characters in style tags', () => {
const Interpolation = styled.div`
& > span {
color: blue;
}
`;
const result = renderToStaticMarkup(
hello world
);
expect(result).toMatchInlineSnapshot(
`"hello world
"`
);
});
});