-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Adding more component jest snapshots #30
Adding more component jest snapshots #30
Conversation
I'm reviewing just the last commit in this PR since the bulk of the changes have already been reviewed in #29 - this is a branch off of that feature branch. @marcelomorgado You added snapshots for screens but not components in this PR, right? Are there any presentational components we don't have snapshots for you? |
demo/screens/Home.test.js
Outdated
describe("Home", () => { | ||
jest.useFakeTimers(); | ||
beforeEach(() => { | ||
NavigationTestUtils.resetInternalState(); |
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.
@marcelomorgado I think for any screens that also happen to be presentational (that don't have any internal state or lifecycle hooks), we probably don't need to import NavigationTestUtils
and use resetInternalState
, right?
On that topic, would it be easier to keep track of which screens are presentational if we moved most of their content to a presentational component and then made the "screen" just render that presentational component? I'm inclined to say yes.
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.
Right.
Yes, make sense.
Some questions:
- Make sense use Screen suffix on file names to avoid name duplication (ex.: screen/ListLandsScreen.js and components/presentational/ListLands.js)?
- Is to do that with all screen components?
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.
- I like that suffix idea.
- Yeah, I think we might as well do this with all screen components.
Thanks!
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.
Hey @pcowgill what do you think?
EthereumQuestionScreen
import React from "react";
import EthereumQuestion from "../components/presentational/EthereumQuestion";
export default class EthereumQuestionScreen extends React.Component {
render() {
return (
<EthereumQuestion
onSignUp={() => this.props.navigation.navigate("EthereumSignUp")}
onSignIn={() => this.props.navigation.navigate("EthereumSignIn")}
/>
);
}
}
EthereumQuestion
import React from "react";
import { Button, StyleSheet, View } from "react-native";
import LargeText from "./LargeText";
import Colors from "../../constants/Colors";
export default function EthereumQuestion(props) {
return (
<View style={styles.container}>
<LargeText>{`Are you new to Ethereum?`}</LargeText>
<View style={styles.buttonView}>
<Button title="Yep" onPress={props.onSignUp} />
</View>
<View style={styles.buttonView}>
<Button title="Nope" onPress={props.onSignIn} />
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Colors.backgroundColor,
alignItems: "center",
justifyContent: "center",
},
buttonView: {
flexDirection: "row",
marginTop: 20,
},
});
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.
This looks great!
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.
Feel free to make changes like this one throughout the repo
demo/screens/Home.test.js
Outdated
import Home from "./Home"; | ||
|
||
describe("Home", () => { | ||
jest.useFakeTimers(); |
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.
Most pure, functional presentational components won't need to useFakeTimers
, right?
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.
Yes, you are right.
demo/screens/LandClaim.test.js
Outdated
|
||
it("renders the component", async () => { | ||
const navigation = { getParam: jest.fn() }; | ||
expect(shallow(<LandClaim navigation={navigation} />)).toMatchSnapshot(); |
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.
I think the snapshot / test split would be more readable if there were a presentational component for most of the jsx in LandClaim that had a shallow snapshot test with no navigation mock, and then this screen shallow-rendered itself with the name of that component like it does now, but the snapshot would be much smaller.
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.
Yes, I agree. 👍
Sorry, I've read literally the title of the issue: "Add jest snapshots for the existing screens", I think that all components should be tested. |
Ah yeah, I should have mentioned components in the issue too. That said, it's a perfectly sensible choice to add snapshots for the components in another PR. But it's probably simplest given the screens/components moving parts we just discussed to do it within this PR this time around |
Ok, I got it. |
Updating Marcelo's snapshots feature branch with the latest from develop
…/tasit into feature/snapshots
Some notes:
|
…ture/snapshots
|
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Co-Authored-By: marcelomorgado <cmarcelom@gmail.com>
Refs #22