<commit_before>import bindMapSetStateToProps from '../bindMapSetStateToProps'
import { SetState } from '../types'

interface S {
    a: number
    b: number
}

interface ExtraP {
    doA: () => void
    doB: (n: number) => void
}

describe('bindMapSetStateToProps', () => {
    it('should bind a function', () => {
        const setState = jest.fn()
        const bindedProps: ExtraP = bindMapSetStateToProps<{}, S, ExtraP>(
            ({}) => (setState: SetState<{}, S>) => ({
                doA: () => setState({ a: 1 }),
                doB: (b: number) => setState({ b })
            }),
            {},
            setState
        )

        expect(bindedProps.doA).toBeDefined()
        expect(bindedProps.doB).toBeDefined()

        bindedProps.doA()

        expect(setState).toHaveBeenCalledWith({ a: 1 })

        bindedProps.doB(2)

        expect(setState).toHaveBeenCalledWith({ b: 2 })
    })

    it('should bind state creators', () => {
        const setState = jest.fn()
        const bindedProps: ExtraP = bindMapSetStateToProps<{}, S, ExtraP>(
            {
                doA: () => ({ a: 1 }),
                doB: (b: number) => ({ b })
            },
            {},
            setState
        )

        expect(bindedProps.doA).toBeDefined()
        expect(bindedProps.doB).toBeDefined()

        bindedProps.doA()

        expect(setState).toHaveBeenCalledWith({ a: 1 })

        bindedProps.doB(2)

        expect(setState).toHaveBeenCalledWith({ b: 2 })
    })
})<commit_msg>test: fix remaining tests<commit_after>import bindMapSetStateToProps from '../bindMapSetStateToProps'
import { SetState } from '../types'

describe('bindMapSetStateToProps', () => {
    describe('when mapSetStateToProps is a function', () => {
        it('should return mapped props', () => {
            const mapSetStateToProps = initialProps => setState => ({
                ...initialProps,
                initialProps,
                setState,
                setVisible: () => setState({ visible: true })
            })
            const fn = jest.fn()
            const props = { foo: 'bar' }

            const boundProps = bindMapSetStateToProps(
                mapSetStateToProps,
                fn,
                props
            )

            expect(boundProps.foo).toBe('bar')
            expect(boundProps.initialProps).toEqual(props)
            expect(boundProps.setState).toBe(fn)
            expect(boundProps.setVisible).toBeDefined()

            boundProps.setState({ baz: 'qux' })

            expect(fn).toHaveBeenCalledWith({ baz: 'qux' })

            boundProps.setVisible()

            expect(fn).toHaveBeenCalledWith({ visible: true })
        })
    })

    describe('when mapSetStateToProps is an object', () => {
        it('should return bound state creators', () => {
            const mapSetStateToProps = {
                setVisibility: visible => ({ visible }),
                setVisible: () => ({ visible: true })
            }
            const fn = jest.fn()
            const props = { foo: 'bar' }

            const boundProps = bindMapSetStateToProps(
                mapSetStateToProps,
                fn,
                props
            ) as any

            expect(boundProps.setVisibility).toBeDefined()
            expect(boundProps.setVisible).toBeDefined()

            boundProps.setVisible()

            expect(fn).toHaveBeenCalledWith({ visible: true })

            boundProps.setVisibility('test')

            expect(fn).toHaveBeenCalledWith({ visible: 'test' })
        })
    })
})
{'fraction_non_alphanumeric': 0.13275329778276734, 'fraction_numerical': 0.002245298905416784, 'mean_word_length': 1.804091266719119, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3859703', 'n_tokens_mistral': 1015, 'n_tokens_neox': 983, 'n_words': 192}