Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
Improve App spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
felixjung committed Dec 6, 2018
1 parent 2d33c8c commit 082f739
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions files/App.spec.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import React from 'react';
import { render } from 'react-testing-library';

import App from './App.js';
import App from './App';

/**
* Having a separate rendering function for your components
* makes it easier to render a separate component for each
* test and reduces boilerplate.
*
* defaultProps help you have sensible defaults that work
* for most tests. You can pass in custom props to customize
* rendering for your current test.
* */
* for most tests.
*/
const defaultProps = {
// This will look more complex for real component.
};

/**
* Having a dedicated test render function for your component
* makes it easy to keep your tests decoupled and reduces
* boilerplate.
*/
const renderApp = (props = {}) =>
render(<App {...{ ...defaultProps, ...props }} />);

describe('App', () => {
/**
* Testing by what your user sees gives you more confidence
* in your tests.
* */
*/
it('should show a title inside the card', () => {
const { getByText } = renderApp();
const heading = getByText('Welcome to SumUp React', { selector: 'h2' });
Expand All @@ -32,7 +33,7 @@ describe('App', () => {
/**
* For something like a logo, it might make sense to use a test-id
* data attribute.
* */
*/
it('should show the SumUp logo', () => {
const { queryByTestId } = renderApp();
expect(queryByTestId('sumup-logo')).toBeInTheDocument();
Expand Down

0 comments on commit 082f739

Please sign in to comment.