|
| 1 | +import React from 'react'; |
| 2 | +import ReactTestUtils from 'react/lib/ReactTestUtils'; |
| 3 | +import FormControls from '../src/FormControls'; |
| 4 | + |
| 5 | +describe('Form Controls', function () { |
| 6 | + describe('Static', function () { |
| 7 | + it('renders a p element wrapped around the given value', function () { |
| 8 | + const instance = ReactTestUtils.renderIntoDocument( |
| 9 | + <FormControls.Static value='v' /> |
| 10 | + ); |
| 11 | + |
| 12 | + const result = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'p'); |
| 13 | + result.props.children.should.equal('v'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('getValue() pulls from either value or children', function () { |
| 17 | + let instance = ReactTestUtils.renderIntoDocument( |
| 18 | + <FormControls.Static value='v' /> |
| 19 | + ); |
| 20 | + |
| 21 | + instance.getValue().should.equal('v'); |
| 22 | + |
| 23 | + instance = ReactTestUtils.renderIntoDocument( |
| 24 | + <FormControls.Static>5</FormControls.Static> |
| 25 | + ); |
| 26 | + |
| 27 | + instance.getValue().should.equal('5'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('throws an error if both value and children are provided', function () { |
| 31 | + const testData = { value: 'blah', children: 'meh' }; |
| 32 | + const result = FormControls.Static.propTypes.children(testData, 'children', 'Static'); |
| 33 | + |
| 34 | + result.should.be.instanceOf(Error); |
| 35 | + }); |
| 36 | + }); |
| 37 | +}); |
0 commit comments