Skip to content

Instantly share code, notes, and snippets.

View alanbsmith's full-sized avatar
👋

Alan B Smith alanbsmith

👋
View GitHub Profile
@alanbsmith
alanbsmith / structuring-our-styled-components-example-modifier-use.jsx
Created December 8, 2017 18:22
structuring-our-styled-components-example-modifier-use
<A
href="https://example.com"
modifiers={['darkGreyText', 'uppercase']}
/>
@alanbsmith
alanbsmith / structuring-our-styled-components-import-short-example.js
Created December 8, 2017 18:29
structuring-our-styled-components-import-short-example
import Card from './blocks/Card';
@alanbsmith
alanbsmith / effective-testing-for-styled-components-clone-repo.sh
Created December 8, 2017 21:16
effective-testing-for-styled-components-clone-repo
$ git clone git@github.com:alanbsmith/jest-snapshot-example.git
$ cd jest-snapshot-example
$ yarn install
@alanbsmith
alanbsmith / effective-testing-for-styled-components-eslint-scripts.sh
Created December 8, 2017 21:18
effective-testing-for-styled-components-eslint-scripts
$ yarn lint:js
$ yarn lint:js:watch
@alanbsmith
alanbsmith / effective-testing-for-styled-components-simple-button.js
Created December 8, 2017 21:20
effective-testing-for-styled-components-simple-button
import styled from 'styled-components';
const Button = styled.button`
background-color: #7D7D7D;
color: #FFF;
`;
export default Button;
@alanbsmith
alanbsmith / effective-testing-for-styled-components-simple-button-enzyme-test.js
Created December 8, 2017 21:21
effective-testing-for-styled-components-simple-button-enzyme-test
import { shallow } from ‘enzyme’;
import expect from ‘expect’
import enzymify from ‘expect-enzyme’
expect.extend(enzymify())
describe(‘Button Component’, () => {
it(‘renders a button element’, () => {
const wrapper = shallow(Button);
// this test is basically worthless
expect(wrapper).toBeA(‘button’);
@alanbsmith
alanbsmith / effective-testing-for-styled-components-simple-snapshot.js
Created December 8, 2017 21:23
effective-testing-for-styled-components-simple-snapshot
import React from 'react';
import Button from '../index';
import renderer from 'react-test-renderer';
describe('Button Block', () => {
it('renders correctly', () => {
const tree = renderer
.create(<Button>Submit</Button>)
.toJSON();
expect(tree).toMatchSnapshot();
@alanbsmith
alanbsmith / effective-testing-for-styled-components-button-file-structure.md
Created December 8, 2017 21:24
effective-testing-for-styled-components-button-file-structure
├ Button/
├── __tests__/
| | ├── __snapshots__
| | | ├── index.js.snap // <- Button snapshot
| └── index.js          // <- Test
@alanbsmith
alanbsmith / effective-testing-for-styled-components-file-structure.md
Last active December 8, 2017 21:31
effective-testing-for-styled-components-file-structure
├ lib/
├── blocks/
| ├── Button/
| | ├── __tests__/
| | | ├── Icon.js  // <- Element Test
| | | └── index.js // <- Block Test
| | ├── Icon.js    // <- Element
| | ├── Text.js    // <- Element
| | └── index.js // &lt;- Block
@alanbsmith
alanbsmith / effective-testing-for-styled-components-button-styles.js
Created December 8, 2017 21:32
effective-testing-for-styled-components-button-styles
// lib/blocks/Button/index.js
import styled from 'styled-components';
import { rgba, lighten } from 'polished';
const Button = styled.button`
background-color: #7D7D7D;
border-radius: 2px;
border: solid 1px transparent;