// eslint-disable-next-line import/no-extraneous-dependencies
import { styled } from '@compiled/react';
import { render } from '@testing-library/react';
import React from 'react';
jest.mock('../runtime/is-server-environment', () => ({
isServerEnvironment: () => false,
}));
describe('browser', () => {
beforeEach(() => {
// Reset style tags in head before each test so that it will remove styles
// injected by test
document.head.querySelectorAll('style').forEach((styleElement) => {
styleElement.textContent = '';
});
});
it('should not render styles inline', () => {
const StyledDiv = styled.div`
font-size: 12px;
`;
const { baseElement } = render(hello world);
expect(baseElement.innerHTML).toMatchInlineSnapshot(
`"
"`
);
});
it('should only render one style block to the head if its already been moved', () => {
const StyledDiv = styled.div`
font-size: 14px;
`;
render(
<>
hello world
hello world
>
);
expect(document.head.innerHTML).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;
}
:link,
:focus-visible {
color: white;
}
:visited {
color: pink;
}
@media (max-width: 800px) {
:active {
color: black;
}
:focus {
color: yellow;
}
:hover,
:focus-visible {
color: grey;
}
}
`;
render(Atlassian Design System);
expect(document.head.innerHTML.split('').join('\n')).toMatchInlineSnapshot(`
"
"
`);
});
});