diegohaz / arc

React starter kit based on Atomic Design
https://arc.js.org
2.92k stars 292 forks source link

[redux] jest running test cases on containers components #210

Closed brijesh-pant closed 7 years ago

brijesh-pant commented 7 years ago

screenshot from 2017-04-09 13 36 55 Hi @diegohaz , First of all thanks for the wonderful boilerplate to follow atomic design. I'm trying to run test cases using jest. While components are testing perfectly with proper code coverage. I'm having problems with containers which jest is trying to run test cases on and produces less coverage for those.

I'm wondering how do I have to create test cases for the containers I create. For e.g when I created a component using redux form and a corresponding container for the same components, jest don't show any code coverage on those.

But when I create a component like LocaleSwitch and use a container for that, jest shows up less code coverage on the LocaleSwitchContainer.

Creating test cases for actions for localeswitch redux state also shows up the same less code coverage.

Here is a sample for the code

import { connect } from 'react-redux'

import { LocaleSwitch } from 'components/organisms';
import { i18nMessages } from 'actions/i18nActions';

const LocaleSwitchContainer = props => <LocaleSwitch {...props} />

const mapStateToProps = ({ i18n }) => ({
  locale: i18n.locale,
})

const mapDispatchToProps = (dispatch) => ({
  onChangeLocale: (locale) => dispatch(i18nMessages.request({ locale })),
})

export default connect(mapStateToProps, mapDispatchToProps)(LocaleSwitchContainer)

Do I need to create mockStore for the containers I'm using ? Please let me know if anything is unclear. I'll elaborate more on it.

diegohaz commented 7 years ago

Hi, @brijesh-pant. Sorry about the delay.

It seems that you are using different structure from ARc since you are importing from components/organisms and actions/**.

On ARc example source, jest doesn't see containers (because we mock them here) and therefore doesn't generate coverage status for them.

Usually, I don't test containers because they simply use other libraries and internal modules that already test themselves (components, store, redux, redux-form etc.).