diff --git a/src/components/View/__tests__/index-test.js b/src/components/View/__tests__/index-test.js index cc3dd18e..0d8d90cb 100644 --- a/src/components/View/__tests__/index-test.js +++ b/src/components/View/__tests__/index-test.js @@ -7,8 +7,20 @@ import View from '../' import { mount, shallow } from 'enzyme' suite('components/View', () => { + suite('rendered element', () => { + test('is a "div" by default', () => { + const view = shallow() + assert.equal(view.is('div'), true) + }) + + test('is a "span" when inside ', () => { + const view = mount() + assert.equal(view.find('span').length, 1) + }) + }) + test('prop "children"', () => { - const children = 'children' + const children = const view = shallow({children}) assert.equal(view.prop('children'), children) }) diff --git a/src/components/View/index.js b/src/components/View/index.js index 38adb1ea..0456530b 100644 --- a/src/components/View/index.js +++ b/src/components/View/index.js @@ -50,9 +50,18 @@ class View extends Component { style: {} }; - constructor(props, context) { - super(props, context) - this._normalizeEventForHandler = this._normalizeEventForHandler.bind(this) + static childContextTypes = { + isInAButtonView: PropTypes.bool + }; + + static contextTypes = { + isInAButtonView: PropTypes.bool + }; + + getChildContext() { + return { + isInAButtonView: this.props.accessibilityRole === 'button' + } } render() { @@ -72,6 +81,7 @@ class View extends Component { const props = { ...other, + component: this.context.isInAButtonView ? 'span' : 'div', onClick: this._normalizeEventForHandler(this.props.onClick), onClickCapture: this._normalizeEventForHandler(this.props.onClickCapture), onTouchCancel: this._normalizeEventForHandler(this.props.onTouchCancel),