|
| 1 | +/* eslint-disable jsx-quotes */ |
| 2 | +/* eslint-env jest */ |
| 3 | +import React from 'react' |
| 4 | +import renderer from 'react-test-renderer' |
| 5 | +import plugin from '../babel' |
| 6 | +import css from 'glam'; |
| 7 | + |
| 8 | +const babel = require('babel-core') |
| 9 | + |
| 10 | +describe('emotion/glam', () => { |
| 11 | + describe('babel', () => { |
| 12 | + test('basic', () => { |
| 13 | + const basic = '(<div className="a" css={`color: brown;`}></div>)' |
| 14 | + const {code} = babel.transform(basic, {plugins: [plugin]}) |
| 15 | + expect(code).toMatchSnapshot() |
| 16 | + }) |
| 17 | + |
| 18 | + test('no css attr', () => { |
| 19 | + const basic = '(<div></div>)' |
| 20 | + const {code} = babel.transform(basic, {plugins: [plugin]}) |
| 21 | + expect(code).toMatchSnapshot() |
| 22 | + }) |
| 23 | + |
| 24 | + test('noClassName', () => { |
| 25 | + const basic = '(<div css={`color: brown;`}></div>)' |
| 26 | + const {code} = babel.transform(basic, {plugins: [plugin]}) |
| 27 | + expect(code).toMatchSnapshot() |
| 28 | + }) |
| 29 | + |
| 30 | + test('emptyClassName', () => { |
| 31 | + const basic = '(<div className="" css={`color: brown;`}></div>)' |
| 32 | + const {code} = babel.transform(basic, {plugins: [plugin]}) |
| 33 | + expect(code).toMatchSnapshot() |
| 34 | + }) |
| 35 | + |
| 36 | + test('className as expression', () => { |
| 37 | + const basic = '(<div className={variable} css={`color: brown;`}></div>)' |
| 38 | + const {code} = babel.transform(basic, {plugins: [plugin]}) |
| 39 | + expect(code).toMatchSnapshot() |
| 40 | + }) |
| 41 | + |
| 42 | + test('className as expression string', () => { |
| 43 | + const basic = '(<div className={`test__class\`} css={`color: brown;`} this={`hello\`}></div>)' |
| 44 | + const {code} = babel.transform(basic, {plugins: [plugin]}) |
| 45 | + expect(code).toMatchSnapshot() |
| 46 | + }) |
| 47 | + }) |
| 48 | + |
| 49 | + describe('real', () => { |
| 50 | + test('basic', () => { |
| 51 | + const tree = renderer |
| 52 | + .create( |
| 53 | + <p css={`color: red;`}> |
| 54 | + hello world |
| 55 | + </p> |
| 56 | + ) |
| 57 | + .toJSON() |
| 58 | + |
| 59 | + expect(tree).toMatchSnapshot() |
| 60 | + }) |
| 61 | + |
| 62 | + test('nested', () => { |
| 63 | + const props = { online: false, radius: 5 } |
| 64 | + |
| 65 | + const tree = renderer |
| 66 | + .create( |
| 67 | + <div className="a" css={`color: brown;`}> |
| 68 | + <p className="foo" css={`color: blue;`}>Hello</p> |
| 69 | + <p className="foo" css={`color: green;`}>World</p> |
| 70 | + <p |
| 71 | + className={` ${css` |
| 72 | + color: red; |
| 73 | + border-radius: ${props.radius}; |
| 74 | + &:hover { |
| 75 | + font-weight: bold; |
| 76 | + color: ${props.online ? 'green' : 'gray'}; |
| 77 | + } |
| 78 | + `}`} |
| 79 | + > |
| 80 | + hello world |
| 81 | + </p> |
| 82 | + </div> |
| 83 | + ) |
| 84 | + .toJSON() |
| 85 | + |
| 86 | + expect(tree).toMatchSnapshot() |
| 87 | + }) |
| 88 | + }) |
| 89 | +}) |
0 commit comments