|
| 1 | +import React, { Component } from 'react' |
| 2 | +import ReactDOM from 'react-dom' |
| 3 | +import { mount } from 'enzyme' |
| 4 | + |
| 5 | +import { propper } from './index.js' |
| 6 | + |
| 7 | +class ClassComp extends Component { |
| 8 | + render () { |
| 9 | + const { counter } = this.props |
| 10 | + |
| 11 | + return <>{counter}</> |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +const FuncComp = ({ counter }) => { |
| 16 | + return <div></div> |
| 17 | +} |
| 18 | + |
| 19 | +test('the propper export is a function', () => { |
| 20 | + expect(propper).toBeInstanceOf(Function) |
| 21 | +}) |
| 22 | + |
| 23 | +test('the propper export is a callable function which returns a function', () => { |
| 24 | + const reduceProps = () => ({}) |
| 25 | + |
| 26 | + expect(propper(reduceProps)).toBeInstanceOf(Function) |
| 27 | +}) |
| 28 | + |
| 29 | +test('the reduceProps function is called', () => { |
| 30 | + const mockReduceProps = jest.fn(ownProps => ({ |
| 31 | + truthyCount: ownProps.items.filter(a => a).length |
| 32 | + })) |
| 33 | + const ProppedComp = propper(mockReduceProps)(ClassComp) |
| 34 | + |
| 35 | + const component = mount(<ProppedComp items={[true, true, false]} />) |
| 36 | + |
| 37 | + expect(component).toMatchSnapshot() |
| 38 | + //console.log(component.instance().props); |
| 39 | + // expect(component.childAt(0).props()).toEqual({ truthyCount: 2, forceUpdate: () => {} }) |
| 40 | + expect(Object.keys(component.childAt(0).props()).length).toEqual(2) |
| 41 | + expect(component.childAt(0).props().forceUpdate).toBeInstanceOf( Function ) |
| 42 | + expect(component.childAt(0).props().truthyCount).toEqual(2) |
| 43 | + expect(mockReduceProps.mock.calls.length).toBe(1) |
| 44 | +}) |
| 45 | + |
| 46 | +/* |
| 47 | +const component = renderer.create( |
| 48 | + <Link page="http://www.facebook.com">Facebook</Link>, |
| 49 | +); |
| 50 | +let tree = component.toJSON(); |
| 51 | +expect(tree).toMatchSnapshot(); |
| 52 | +
|
| 53 | +// manually trigger the callback |
| 54 | +tree.props.onMouseEnter(); |
| 55 | +// re-rendering |
| 56 | +tree = component.toJSON(); |
| 57 | +expect(tree).toMatchSnapshot(); |
| 58 | +
|
| 59 | +// manually trigger the callback |
| 60 | +tree.props.onMouseLeave(); |
| 61 | +// re-rendering |
| 62 | +tree = component.toJSON(); |
| 63 | +expect(tree).toMatchSnapshot();*/ |
0 commit comments