Skip to content
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

Open
rowlandekemezie opened this issue Oct 8, 2016 · 9 comments
Open

Add tests to increase coverage #356

rowlandekemezie opened this issue Oct 8, 2016 · 9 comments

Comments

@rowlandekemezie
Copy link

No description provided.

@tomchentw
Copy link
Owner

I'd appreciate some help from contributors!

@johnstew
Copy link

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.

@johnstew
Copy link

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.

@ghost
Copy link

ghost commented Oct 29, 2016

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 .travis.yml file), but the command you should be using is npm test -- --coverage. This will not only run your tests but also give you a coverage report.

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.

@johnstew
Copy link

Yea so I've been running npm test for now without the code coverage because I was just interested in getting the tests up and running. I feel like once I get some good direction from Tom & Co about what I have above and if I am going down the right path for how they want the project tests structured then I will begin to generate the test coverage report. Also, @danielehrlich thank you! I'm glad I'm going about it the right away (or so we think). 😄

@tomchentw
Copy link
Owner

Anyone interested?

@oshalygin
Copy link
Collaborator

I'll be picking this one up @tomchentw I'll start a feature branch and progressively start increasing coverage.

@oshalygin oshalygin self-assigned this Jul 6, 2017
@tomchentw
Copy link
Owner

@oshalygin great!

oshalygin added a commit to oshalygin/react-google-maps that referenced this issue Jul 24, 2017
- 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
oshalygin added a commit to oshalygin/react-google-maps that referenced this issue Jul 24, 2017
- 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
oshalygin added a commit to oshalygin/react-google-maps that referenced this issue Jul 25, 2017
- 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
oshalygin added a commit to oshalygin/react-google-maps that referenced this issue Jul 25, 2017
- 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
@ningo-agilityio
Copy link

It seems that the render function SimpleGoogleMap wasn't called, I debug with console.log and it didn't move there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants