{"size": 1378, "ext": "js", "max_stars_repo_path": "src/__tests__/makeReducer.js", "max_stars_repo_name": "cevr/arranger", "max_stars_repo_stars_event_min_datetime": "2019-06-04T19:20:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-16T06:25:39.000Z", "max_issues_repo_path": "src/__tests__/makeReducer.js", "max_issues_repo_name": "cevr/re-enhance", "max_issues_repo_issues_event_min_datetime": "2019-05-13T09:53:42.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-04T20:16:29.000Z", "max_forks_repo_path": "src/__tests__/makeReducer.js", "max_forks_repo_name": "cevr/re-enhance", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 15, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 27.0196078431, "max_line_length": 58, "alphanum_fraction": 0.442670537}
/* eslint-env jest */

import testWrapper from '../utils/testWrapper'
import makeReducer from '../makeReducer'

test('makeReducer', () => {
    const wrapper = testWrapper(
        makeReducer(
            'state',
            'dispatch',
            (state, action) => {
                switch (action.type) {
                    case 'INCREMENT':
                        return { count: state.count + 1 }
                    default:
                        return state
                }
            },
            { count: 0 },
        ),
        {},
    )

    expect(wrapper.getProps().state).toEqual({ count: 0 })
    wrapper.getProps().dispatch({ type: 'INCREMENT' })
    expect(wrapper.getProps().state).toEqual({ count: 1 })
})

test('makeReducer memo', () => {
    const wrapper = testWrapper(
        makeReducer(
            'state',
            'dispatch',
            (state, action) => {
                switch (action.type) {
                    case 'INCREMENT':
                        return { count: state.count + 1 }
                    default:
                        return state
                }
            },
            () => ({ count: 0 }),
        ),
        {},
    )

    expect(wrapper.getProps().state).toEqual({ count: 0 })
    wrapper.getProps().dispatch({ type: 'INCREMENT' })
    expect(wrapper.getProps().state).toEqual({ count: 1 })
})
