{"size": 2137, "ext": "js", "max_stars_repo_path": "src/App.test.js", "max_stars_repo_name": "alialfredji/fia", "max_stars_repo_stars_event_min_datetime": "2019-05-19T21:35:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-26T00:45:54.000Z", "max_issues_repo_path": "src/App.test.js", "max_issues_repo_name": "alialfredji/fia", "max_issues_repo_issues_event_min_datetime": "2019-05-21T12:24:40.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-21T12:24:40.000Z", "max_forks_repo_path": "src/App.test.js", "max_forks_repo_name": "alialfredji/fia", "max_forks_repo_forks_event_min_datetime": "2019-05-22T15:32:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-22T15:32:05.000Z"}
{"max_stars_count": 4, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 27.0506329114, "max_line_length": 86, "alphanum_fraction": 0.6368741226}
/**
 * About Testing Containers
 * ------------------------
 *
 * `App` is a container, it needs a running store and a `Provider`
 * to run properly.
 *
 * We can't really test the default export (the container) as such, so
 * for that particular case we modified the default CRA test and actually
 * expect it to throw errors.
 *
 * Unit Testing is better suited for **pure components**. You should put
 * a good deal of effort in architecturing your app so that it renders as
 * a simple chain of pure components.
 *
 * Deep nesting containers (Redux connected components) lead to troubles!
 */

import React from 'react'
import ReactDOM from 'react-dom'
import AppContainer from './App'

// Jest has some troubles with mocking the console
// https://stackoverflow.com/questions/44596915/jest-mocking-console-error-tests-fails
const spyConsole = (method = 'log') => {
    const original = console[method]
    console[method] = jest.fn()
    console[method].mockClear = () => {
        console[method] = original
    }

    return console[method]
}

it('crashes if rendered as container', () => {
    const spy = spyConsole('error')
    const div = document.createElement('div')

    expect(() => {
        ReactDOM.render(<AppContainer />, div)
    }).toThrow()

    ReactDOM.unmountComponentAtNode(div)
    spy.mockClear()
})


/**
 * If you really want to test connected containers you need to replicate
 * a realistic state for your application.
 *
 * It is not really difficult, and the Redux DevTools help a lot in this task,
 * but it is quite a hassle to me.
 *
 * I still prefer to test `dumb components`.
 */

// eslint-disable-next-line
import ContextProvider from 'lib/ContextProvider'

it('renders with a lot of troubles', () => {
    const div = document.createElement('div')

    ReactDOM.render((
        <ContextProvider reducers={{
            app: () => ({
                name: 'My Custom App Name',
            }),
            locale: () => ({
                locale: 'it',
            }),
        }}>
            <AppContainer />
        </ContextProvider>
    ), div)

    ReactDOM.unmountComponentAtNode(div)
})
