-
Notifications
You must be signed in to change notification settings - Fork 935
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
Add tests to increase coverage #356
Comments
I'd appreciate some help from contributors! |
I'd be interested in helping write some tests. I'm going to go ahead and take a stab at writing some and will submit PR for review once I feel I have some good progress. |
Alright so after playing around with this for a bit. I wanted to try and understand more about what exactly we should be using and doing for writing these tests. I initially tried using React's test renderer and Jest's snapshots to test the GoogleMap component but ran into this issue jestjs/jest#1353. The recommended solve there was trying a number of different things but ultimately I had to install enzyme, enzyme-to-json, and react-addons-test-utils. I was successfully then able to go ahead and create the snapshots and do a basic render test with the GoogleMap. import React from "react";
import { withGoogleMap, GoogleMap } from "../index";
import { shallow } from 'enzyme';
import { shallowToJson } from 'enzyme-to-json';
import _ from "lodash";
const SimpleGoogleMap = withGoogleMap(props => (
<GoogleMap
ref={props.onMapLoad}
defaultZoom={3}
defaultCenter={{ lat: -25.363882, lng: 131.044922 }}
onClick={props.onMapClick}
/>
));
describe(`GoogleMap`, () => {
it(`should render`, () => {
const googleMap = shallow(
<SimpleGoogleMap
containerElement={
<div style={{ height: `100%` }} />
}
mapElement={
<div style={{ height: `100%` }} />
}
onMapLoad={_.noop}
onMapClick={_.noop}
/>
);
let tree = shallowToJson(googleMap);
expect(tree).toMatchSnapshot();
});
}); I'm hoping some of the other contributors can chime in here and let me know if this is the direction I should be moving or if this is not really the test setup you are looking for. |
When you were running tests, what command did you use? It took me forever to find the correct one (you can see it in the Also on a side note, I like how you went about the tests. I looked at testing a little bit ago, and as I was writing them I had to do a whole lot of import statements as well, which was weird because the test files currently have no import statements in them (that reference node_modules). Because of that it's hard to know what the eventual vision is of Tom & Co is, but you have a very nice start. |
Yea so I've been running |
Anyone interested? |
I'll be picking this one up @tomchentw I'll start a feature branch and progressively start increasing coverage. |
@oshalygin great! |
- The build script is updated to exclude any test files matching the pattern of spec.js. - Additionally, the chai assertion library is added to provide rich assertions in testing Related tomchentw#356
- This is the initial foray into building out solid test coverage across the library. Not all functions and components are tested with this commit, this is merely a starting point. - All functions that are consumed internally within the component are now exported so that they can be tested individually with varying test cases to ensure proper functionality. - The approach to testing taken here is to place test code right next to application code so that it is readily visible which files have test coverage and which dont, regardless of what the coverage report shows. For this reason, the __test__ folder is deprecated and the associated test files are moved out. - Instead of using Jest directly, we are leveraging react-scripts to run the tests and coverage for us. This is done intentionally as that library includes the necessary Jest configuration to properly mock depedendencies and unmock used dependencies such as lodash. In the future, that configuration will be pulled into this library and we will deprecate consumption of third party dependencies such as react-scripts. Related tomchentw#356
- This is the initial foray into building out solid test coverage across the library. Not all functions and components are tested with this commit, this is merely a starting point. - All functions that are consumed internally within the component are now exported so that they can be tested individually with varying test cases to ensure proper functionality. - The approach to testing taken here is to place test code right next to application code so that it is readily visible which files have test coverage and which dont, regardless of what the coverage report shows. For this reason, the __test__ folder is deprecated and the associated test files are moved out. - Instead of using Jest directly, we are leveraging react-scripts to run the tests and coverage for us. This is done intentionally as that library includes the necessary Jest configuration to properly mock depedendencies and unmock used dependencies such as lodash. In the future, that configuration will be pulled into this library and we will deprecate consumption of third party dependencies such as react-scripts. Related tomchentw#356
- This is the initial foray into building out solid test coverage across the library. Not all functions and components are tested with this commit, this is merely a starting point. - All functions that are consumed internally within the component are now exported so that they can be tested individually with varying test cases to ensure proper functionality. - The approach to testing taken here is to place test code right next to application code so that it is readily visible which files have test coverage and which dont, regardless of what the coverage report shows. For this reason, the __test__ folder is deprecated and the associated test files are moved out. - Instead of using Jest directly, we are leveraging react-scripts to run the tests and coverage for us. This is done intentionally as that library includes the necessary Jest configuration to properly mock depedendencies and unmock used dependencies such as lodash. In the future, that configuration will be pulled into this library and we will deprecate consumption of third party dependencies such as react-scripts. Related tomchentw#356
It seems that the render function |
No description provided.
The text was updated successfully, but these errors were encountered: