Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save alanbsmith/80bc5d010e9ff76b45ef52057440ce00 to your computer and use it in GitHub Desktop.

Select an option

Save alanbsmith/80bc5d010e9ff76b45ef52057440ce00 to your computer and use it in GitHub Desktop.
effective-testing-for-styled-components-button-test-with-theme
// lib/blocks/Button/__tests__/index.js
import React from 'react';
import Button from '../index';
import 'jest-styled-components';
import { renderWithTheme } from '__tests__/helpers';
describe('Button Block', () => {
it('renders correctly', () => {
const tree = renderWithTheme(
<Button>
<Button.Text>Login</Button.Text>
<Button.Icon name="home" />
</Button>
).toJSON();
expect(tree).toMatchSnapshot();
});
it('adds the primary modifier', () => {
const tree = renderWithTheme(
<Button modifiers={['primary']}>
<Button.Text>Login</Button.Text>
<Button.Icon name="home" />
</Button>
).toJSON();
expect(tree).toMatchSnapshot();
});
it('adds the secondary modifier', () => {
const tree = renderWithTheme(
<Button modifiers={['secondary']}>
<Button.Text>Login</Button.Text>
<Button.Icon name="home" />
</Button>
).toJSON();
expect(tree).toMatchSnapshot();
});
it('adds the disabled modifier', () => {
const tree = renderWithTheme(
<Button modifiers={['disabled']}>
<Button.Text>Login</Button.Text>
<Button.Icon name="home" />
</Button>
).toJSON();
expect(tree).toMatchSnapshot();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment