-
Notifications
You must be signed in to change notification settings - Fork 667
(WIP) Level-up Jest & Enzyme #1648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: vojtechszocs If they are not already assigned, you can assign the PR to them by writing The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@spadgett There are currently some post-upgrade Enzyme related errors, I need to look into those. /cc @alecmerdler |
|
@mareklibra @rawagner FYI, this PR customizes Jest snapshot file resolution, putting snapshot files next to test files. |
|
@vojtechszocs please setup the |
|
@vojtechszocs: PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
Note to self: add |
|
@vojtechszocs are you going to complete this soon? The dev console needs snapshots. Otherwise we'll need to do some updates so our plugin functions in the interim |
|
What is the value of snapshot tests versus normal unit tests? It seems to unnecessarily couple the DOM output to the implementation, doesn't test the component logic, and makes it harder to follow TDD. |
|
Snapshots are useful for testing data transformations. ie input -> json output I also find snapshots to be useful for components which are rendering html elements which have CSS that couples the rules to the structure. eg. using But simply snapshotting all react components does not make sense. |
@christianvogt I'm currently finalizing my work on testing actual plugins, i.e. validating their extensions, as part of the Console build (like we discussed before). I'll get back to this PR right after that. This PR is still WIP since I've encountered some weird Enzyme-related errors once I bumped Jest & related deps from
@alecmerdler Snapshot tests ensure that serialization of the given object yields the same results every time you run those tests. The object being serialized can be anything, but developers often associate snapshot tests with React components. Based on the premise that a React component is essentially a function taking inputs (props, state, context) and producing rendered markup (JSX), snapshot tests guard against regressions that might occur in component's rendered JSX. So, for React components, it's a way to ensure rendered UI doesn't change unexpectedly. If it does, and the change was intentional/expected, you can update the snapshot to make the test pass again.
React components should be snapshot-tested in isolation, i.e. rendered in const Bar: React.SFC<any> = (props) => {
return <div className="bar">
Hello {props.text}!
</div>
};
const Foo: React.SFC = () => {
return <div className="foo">
<Bar text="Bar" />
</div>
};
Component logic can be tested by simulating interaction with component's DOM elements, i.e. using Enzyme wrapper. You are testing a React component as a unit, instead of testing its individual methods. As for TDD, I think it's best to complement it with different techniques.
Fully agreed. Just like 100% test coverage just for the sake of having it doesn't make sense. |
|
Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle stale |
|
@vojtechszocs: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
Stale issues rot after 30d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle rotten |
|
Rotten issues close after 30d of inactivity. Reopen the issue by commenting /close |
|
@openshift-bot: Closed this PR. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Dependency changes
jest,jest-cli,ts-jestfrom21.xto24.x(latest)enzyme-adapter-react-16from1.12.1to1.13.2(latest)@types/jestenzyme-to-jsonTS config changes
compilerOptions.typesreferencing Jest and Jasmine typingsJest config changes
jest.config.jsjsWithTspreset which reflects theallowJs:truesetting intsconfig.jsonbefore-tests.jsviasetupFilesAfterEnvfollowing Enzyme setup recommendationts-jestwithisolatedModules:true(otherwise, the updated Jest runner gets stuck)snapshotResolver.jsthat allows test vs. snapshot co-locationTest vs. Snapshot co-location
Jest snapshot files have the same extension as their test counterparts.
/cc @christianvogt @spadgett