Created
September 8, 2018 10:40
-
-
Save MicheleBertoli/ea08aa9979e873666f3e3276c2f9c2ea to your computer and use it in GitHub Desktop.
Styled Component v4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import styled from 'styled-components' | |
import renderer from 'react-test-renderer' | |
import { shallow, mount } from 'enzyme' | |
import { render } from 'react-testing-library' | |
const Button = styled.button` | |
color: red; | |
` | |
test('it works', () => { | |
expect(renderer.create(<Button />).toJSON()).toMatchSnapshot( | |
'react-test-renderer' | |
) | |
expect(shallow(<Button />)).toMatchSnapshot('shallow') | |
expect(mount(<Button />)).toMatchSnapshot('mount') | |
expect(render(<Button />).container.firstChild).toMatchSnapshot( | |
'react-testing-library' | |
) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Jest Snapshot v1, https://goo.gl/fbAQLP | |
exports[`it works: mount 1`] = ` | |
<ForwardRef> | |
<BaseStyledComponent | |
forwardedClass={ | |
Object { | |
"$$typeof": Symbol(react.forward_ref), | |
"attrs": undefined, | |
"componentStyle": ComponentStyle { | |
"componentId": "sc-bdVaJa", | |
"isStatic": true, | |
"lastClassName": "rOCEJ", | |
"rules": Array [ | |
" | |
color: red; | |
", | |
], | |
}, | |
"displayName": "styled.button", | |
"render": [Function], | |
"styledComponentId": "sc-bdVaJa", | |
"target": "button", | |
"warnTooManyClasses": [Function], | |
"withComponent": [Function], | |
} | |
} | |
forwardedRef={null} | |
> | |
<button | |
className="sc-bdVaJa rOCEJ" | |
/> | |
</BaseStyledComponent> | |
</ForwardRef> | |
`; | |
exports[`it works: react-test-renderer 1`] = ` | |
<button | |
className="sc-bdVaJa rOCEJ" | |
/> | |
`; | |
exports[`it works: react-testing-library 1`] = ` | |
<button | |
class="sc-bdVaJa rOCEJ" | |
/> | |
`; | |
exports[`it works: shallow 1`] = ` | |
<BaseStyledComponent | |
forwardedClass={ | |
Object { | |
"$$typeof": Symbol(react.forward_ref), | |
"attrs": undefined, | |
"componentStyle": ComponentStyle { | |
"componentId": "sc-bdVaJa", | |
"isStatic": true, | |
"lastClassName": "rOCEJ", | |
"rules": Array [ | |
" | |
color: red; | |
", | |
], | |
}, | |
"displayName": "styled.button", | |
"render": [Function], | |
"styledComponentId": "sc-bdVaJa", | |
"target": "button", | |
"warnTooManyClasses": [Function], | |
"withComponent": [Function], | |
} | |
} | |
forwardedRef={null} | |
/> | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment