Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

psammead-test-helpers - use react-testing-library #107

Closed
wants to merge 4 commits into from

Conversation

sareh
Copy link
Contributor

@sareh sareh commented Dec 5, 2018

Resolves #95

To see the impact that such a change has on snapshot tests, you can look at this Simorgh PR bbc/simorgh#1050

When the shouldMatchSnapshot is used currently, we get this:

exports[`Headings with headline data should render correctly 1`] = `
<ForwardRef
  text="This is a headline!"
>
  This is a headline!
</ForwardRef>
`;

Reference: bbc/simorgh#1026

After this PR, if we use shouldMatchSnapshot, we get this output:

exports[`Headings with headline data should render correctly 1`] = `
<DocumentFragment>
  .c0 {
  color: #222222;
  font-family: ReithSerifNewsMedium,Helvetica,Arial,sans-serif;
  margin: 0;
  padding: 2rem 0 1rem 0;
  font-size: 1.75em;
  line-height: 2rem;
}

@media (min-width:20em) and (max-width:37.4375em) {
  .c0 {
    font-size: 2em;
    line-height: 2.25rem;
  }
}

@media (min-width:37.5em) {
  .c0 {
    font-size: 2.75em;
    line-height: 3rem;
  }
}

<h1
    class="c0"
  >
    This is a headline!
  </h1>
</DocumentFragment>
`;

Reference:
https://github.com/BBC-News/simorgh/blob/cade24c1c1853c5329298b49cd7b290662a46af6/src/app/containers/Header/__snapshots__/index.test.jsx.snap in PR bbc/simorgh#1050

  • Change shouldMatchSnapshot and isNull to use react-testing-library.

  • Installed dev dependencies react & react-dom since they're needed by react-testing-library and the existing react-test-renderer.

  • Tests added for new features

  • Test engineer approval

…ry'. Installed dev dependencies 'react' & 'react-dom' since they're needed by 'react-testing-library' and the existing 'react-test-renderer'
@sareh sareh added this to PR In Progress in Articles via automation Dec 5, 2018
@sareh sareh moved this from PR In Progress to 1st Code review in Articles Dec 5, 2018
@dr3 dr3 assigned sareh Dec 5, 2018
"jest-styled-components": "^6.3.1"
},
"devDependencies": {
"react": "^16.6.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run this locally I dont need react and react-dom? Are you sure these are needed?

"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-test-renderer": "^16.6.3",
"react-testing-library": "^5.3.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a dev library, I think these should be dependencies not devDependencies

import 'jest-styled-components';
import ShallowRenderer from 'react-test-renderer/shallow';

export const shouldMatchSnapshot = (title, component) => {
it(title, () => {
const tree = renderer.create(component).toJSON();
expect(tree).toMatchSnapshot();
const { asFragment } = render(component);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running this on psammead-headings I go from

exports[`Headline component should render correctly 1`] = `
.c0 {
  color: #222222;
  font-family: ReithSerifNewsMedium,Helvetica,Arial,sans-serif;
  margin: 0;
  padding: 2rem 0 1rem 0;
  font-size: 1.75em;
  line-height: 2rem;
}

@media (min-width:20em) and (max-width:37.4375em) {
  .c0 {
    font-size: 2em;
    line-height: 2.25rem;
  }
}

@media (min-width:37.5em) {
  .c0 {
    font-size: 2.75em;
    line-height: 3rem;
  }
}

<h1
  className="c0"
>
  This is my headline.
</h1>
`;

to

exports[`Headline component should render correctly 1`] = `
<DocumentFragment>
  <h1
    class="sc-bdVaJa gMUPYM"
  >
    This is my headline.
  </h1>
</DocumentFragment>

It feels like were losing a lot of information here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. 🤔 Will look into why it's not including the styles in this case, but was when I included it in Simorgh container. I'm not sure about the source of the inconsistency.

@dr3 dr3 moved this from 1st Code review to PR In Progress in Articles Dec 5, 2018
@dr3 dr3 assigned dr3 and sareh and unassigned sareh and dr3 Dec 6, 2018
@dr3
Copy link
Contributor

dr3 commented Dec 7, 2018

Have raised testing-library/react-testing-library#236 because of the issue found linking these packages locally

@ChrisBAshton
Copy link
Contributor

Decided in standup yesterday we'd close this ticket for now.

Thanks for looking at this, Sareh.

Articles automation moved this from PR In Progress to Done Dec 12, 2018
@sareh sareh deleted the react-testing-library branch December 13, 2018 00:41
@ChrisBAshton ChrisBAshton removed this from Done in Articles Jan 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants