|
| 1 | +import composeProps from '../src/composeProps'; |
| 2 | + |
| 3 | +describe('composeProps', () => { |
| 4 | + it('composeProps all', () => { |
| 5 | + const aChange = jest.fn(); |
| 6 | + const aBlur = jest.fn(); |
| 7 | + const bChange = jest.fn(); |
| 8 | + const sourceProps = { value: '11', onChange: aChange, onBlur: aBlur }; |
| 9 | + const patchProps = { onChange: bChange, placeholder: 'x' }; |
| 10 | + |
| 11 | + const props = composeProps(sourceProps, patchProps, true); |
| 12 | + props.onChange(); |
| 13 | + props.onBlur(); |
| 14 | + expect(aChange).toHaveBeenCalled(); |
| 15 | + expect(aBlur).toHaveBeenCalled(); |
| 16 | + expect(bChange).toHaveBeenCalled(); |
| 17 | + expect(Object.keys(props)).toEqual([ |
| 18 | + 'value', |
| 19 | + 'onChange', |
| 20 | + 'onBlur', |
| 21 | + 'placeholder', |
| 22 | + ]); |
| 23 | + }); |
| 24 | + it('composeProps just func', () => { |
| 25 | + const aChange = jest.fn(); |
| 26 | + const aBlur = jest.fn(); |
| 27 | + const bChange = jest.fn(); |
| 28 | + const sourceProps = { value: '11', onChange: aChange, onBlur: aBlur }; |
| 29 | + const patchProps = { onChange: bChange, placeholder: 'x' }; |
| 30 | + |
| 31 | + const props = composeProps(sourceProps, patchProps); |
| 32 | + props.onChange(); |
| 33 | + props.onBlur(); |
| 34 | + expect(aChange).toHaveBeenCalled(); |
| 35 | + expect(aBlur).toHaveBeenCalled(); |
| 36 | + expect(bChange).toHaveBeenCalled(); |
| 37 | + expect(Object.keys(props)).toEqual(['value', 'onChange', 'onBlur']); |
| 38 | + }); |
| 39 | +}); |
0 commit comments