-
Notifications
You must be signed in to change notification settings - Fork 55
psammead-test-helpers - use react-testing-library #107
Conversation
…ry'. Installed dev dependencies 'react' & 'react-dom' since they're needed by 'react-testing-library' and the existing 'react-test-renderer'
"jest-styled-components": "^6.3.1" | ||
}, | ||
"devDependencies": { | ||
"react": "^16.6.3", |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Have raised testing-library/react-testing-library#236 because of the issue found linking these packages locally |
Decided in standup yesterday we'd close this ticket for now. Thanks for looking at this, Sareh. |
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:Reference: bbc/simorgh#1026
After this PR, if we use
shouldMatchSnapshot
, we get this output: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
andisNull
to usereact-testing-library
.Installed dev dependencies
react
&react-dom
since they're needed byreact-testing-library
and the existingreact-test-renderer
.Tests added for new features
Test engineer approval