integration.test.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { h, createContext, render } from 'preact';
  2. import { useContext } from 'preact/hooks';
  3. import { setup, extractCss } from 'goober';
  4. import { createGlobalStyles } from '../index';
  5. describe('createGlobalStyles', () => {
  6. it('regular', () => {
  7. setup(h);
  8. const target = document.createElement('div');
  9. const GlobalStyle = createGlobalStyles`
  10. html, body {
  11. background: dodgerblue;
  12. }
  13. `;
  14. render(
  15. <div>
  16. <GlobalStyle />
  17. </div>,
  18. target
  19. );
  20. expect(extractCss()).toMatchSnapshot();
  21. expect(target.innerHTML).toMatchSnapshot();
  22. });
  23. it('with theme', () => {
  24. const ThemeContext = createContext();
  25. const useTheme = () => useContext(ThemeContext);
  26. setup(h, null, useTheme);
  27. const target = document.createElement('div');
  28. const GlobalStyle = createGlobalStyles`
  29. html, body {
  30. margin: 0;
  31. background: ${(props) => props.theme.color};
  32. }
  33. `;
  34. render(
  35. <ThemeContext.Provider value={{ color: 'blue' }}>
  36. <div>
  37. <GlobalStyle />
  38. </div>
  39. </ThemeContext.Provider>,
  40. target
  41. );
  42. expect(extractCss()).toMatchSnapshot();
  43. expect(target.innerHTML).toMatchSnapshot();
  44. });
  45. });