11// @flow
2+ // @jsx jsx
23
3- import * as React from "react " ;
4+ import { jsx } from "@emotion/core " ;
45import * as ReactDOM from "react-dom" ;
56import TestRenderer from "react-test-renderer" ;
6- import { renderToString } from "react-dom/server" ;
7- import { css } from "emotion" ;
8- import { renderStylesToString } from "emotion-server" ;
97import { Box , Flex , useSystem , useResponsive } from "./src/system.js" ;
108
119declare var jest: Function ;
@@ -25,18 +23,18 @@ window.matchMedia = jest.fn().mockImplementation(query => {
2523test ( "support width and height" , ( ) => {
2624 expect ( TestRenderer . create ( < Box width = "100px" height = "10em" /> ) . toJSON ( ) )
2725 . toMatchInlineSnapshot ( `
28- .emotion-0 {
29- box-sizing: border-box;
30- min-width: 0;
31- min-height: 0;
32- width: 100px;
33- height: 10em;
34- }
35-
36- <div
37- className="emotion-0"
38- />
39- ` ) ;
26+ .emotion-0 {
27+ box-sizing: border-box;
28+ min-width: 0;
29+ min-height: 0;
30+ width: 100px;
31+ height: 10em;
32+ }
33+
34+ <div
35+ className="emotion-0"
36+ />
37+ `) ;
4038} ) ;
4139
4240test ( "support numbers in width and height" , ( ) => {
@@ -471,7 +469,7 @@ test("pass is prop to render element other than div", () => {
471469` ) ;
472470} ) ;
473471
474- test ( "css prop does not override props" , ( ) => {
472+ test ( "css prop overrides props" , ( ) => {
475473 expect (
476474 TestRenderer . create (
477475 < div >
@@ -488,70 +486,20 @@ test("css prop does not override props", () => {
488486 box-sizing: border-box;
489487 min-width: 0;
490488 min-height: 0;
491- min-width: 100px;
492- width: 200px;
493- height: 300px;
494- width: 50%;
495- }
496-
497- .emotion-1 {
498- box-sizing: border-box;
499- min-width: 0;
500- min-height: 0;
501- min-width: 100px;
502- width: 200px;
503- height: 300px;
504489 width: 50%;
505- }
506-
507- <div>
508- <div
509- className="emotion-0"
510- />
511- <div
512- className="emotion-1"
513- />
514- </div>
515- ` ) ;
516- } ) ;
517-
518- test ( "className does not override props" , ( ) => {
519- expect (
520- TestRenderer . create (
521- < div >
522- < Flex
523- width = { 1 / 2 }
524- className = { css ( { minWidth : 100 , width : 200 , height : 300 } ) }
525- />
526- < Box
527- width = { 1 / 2 }
528- className = { css ( { minWidth : 100 , width : 200 , height : 300 } ) }
529- />
530- </ div >
531- ) . toJSON ( )
532- ) . toMatchInlineSnapshot ( `
533- .emotion-0 {
534- display: -webkit-box;
535- display: -webkit-flex;
536- display: -ms-flexbox;
537- display: flex;
538- box-sizing: border-box;
539- min-width: 0;
540- min-height: 0;
541490 min-width: 100px;
542491 width: 200px;
543492 height: 300px;
544- width: 50%;
545493}
546494
547495.emotion-1 {
548496 box-sizing: border-box;
549497 min-width: 0;
550498 min-height: 0;
499+ width: 50%;
551500 min-width: 100px;
552501 width: 200px;
553502 height: 300px;
554- width: 50%;
555503}
556504
557505<div>
@@ -606,9 +554,7 @@ test("system media allow to pass responsive styles to css prop and emotion css()
606554 const { media } = useSystem ( ) ;
607555
608556 return (
609- < div
610- className = { css ( media ( { display : [ "block" , "none" ] , color : "#fff" } ) ) }
611- >
557+ < div css = { media ( { display : [ "block" , "none" ] , color : "#fff" } ) } >
612558 < Box css = { media ( { overflow : [ "hidden" , "auto" ] , color : "#000" } ) } />
613559 </ div >
614560 ) ;
@@ -656,13 +602,11 @@ test("system media allow to pass array of rules", () => {
656602
657603 return (
658604 < div
659- className = { css (
660- media ( [
661- { display : "block" , color : "#fff" } ,
662- { display : "none" , color : "#000" } ,
663- { display : "flex" , color : "#666" }
664- ] )
665- ) }
605+ css = { media ( [
606+ { display : "block" , color : "#fff" } ,
607+ { display : "none" , color : "#000" } ,
608+ { display : "flex" , color : "#666" }
609+ ] ) }
666610 >
667611 < Box
668612 css = { media ( [
@@ -749,9 +693,7 @@ test("media util allow to pass responsive styles to css prop and emotion css()",
749693 const App = ( ) => {
750694 const { media } = useSystem ( ) ;
751695 return (
752- < div
753- className = { css ( media ( { display : [ "block" , "none" ] , color : "#fff" } ) ) }
754- >
696+ < div css = { media ( { display : [ "block" , "none" ] , color : "#fff" } ) } >
755697 < Box css = { media ( { overflow : [ "hidden" , "auto" ] , color : "#000" } ) } />
756698 </ div >
757699 ) ;
@@ -846,9 +788,9 @@ test("system paddings allows to use theme for any component", () => {
846788 const { pt, pr, pb, pl, px, py, p } = useSystem ( ) ;
847789 return (
848790 < div >
849- < div className = { css ( [ pt ( 1 ) , pr ( 2 ) , pb ( 3 ) , pl ( 4 ) ] ) } />
850- < div className = { css ( [ px ( 1 ) , py ( 2 ) ] ) } />
851- < div className = { css ( [ p ( 1 ) ] ) } />
791+ < div css = { [ pt ( 1 ) , pr ( 2 ) , pb ( 3 ) , pl ( 4 ) ] } />
792+ < div css = { [ px ( 1 ) , py ( 2 ) ] } />
793+ < div css = { [ p ( 1 ) ] } />
852794 </ div >
853795 ) ;
854796 } ;
@@ -893,9 +835,9 @@ test("system margins allows to use theme for any component", () => {
893835 const { mt, mr, mb, ml, mx, my, m } = useSystem ( ) ;
894836 return (
895837 < div >
896- < div className = { css ( [ mt ( 1 ) , mr ( 2 ) , mb ( 3 ) , ml ( 4 ) ] ) } />
897- < div className = { css ( [ mx ( 1 ) , my ( 2 ) ] ) } />
898- < div className = { css ( [ m ( 1 ) ] ) } />
838+ < div css = { [ mt ( 1 ) , mr ( 2 ) , mb ( 3 ) , ml ( 4 ) ] } />
839+ < div css = { [ mx ( 1 ) , my ( 2 ) ] } />
840+ < div css = { [ m ( 1 ) ] } />
899841 </ div >
900842 ) ;
901843 } ;
0 commit comments