mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-31 01:36:11 +00:00
[fix] disallow text node children of View
Catch text nodes that are not the only child of View. Fixes a case
missing from 0ad6ab948b.
This commit is contained in:
@@ -13,9 +13,20 @@ describe('components/View', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('prop "children"', () => {
|
describe('prop "children"', () => {
|
||||||
test('text node throws error', () => {
|
test('text node throws error (single)', () => {
|
||||||
const children = 'hello';
|
const render = () => shallow(<View>'hello'</View>);
|
||||||
const render = () => shallow(<View>{children}</View>);
|
expect(render).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('text node throws error (array)', () => {
|
||||||
|
const render = () =>
|
||||||
|
shallow(
|
||||||
|
<View>
|
||||||
|
<View />
|
||||||
|
'hello'
|
||||||
|
<View />
|
||||||
|
</View>
|
||||||
|
);
|
||||||
expect(render).toThrow();
|
expect(render).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -51,10 +51,9 @@ class View extends Component {
|
|||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
invariant(
|
React.Children.toArray(this.props.children).forEach(item => {
|
||||||
typeof this.props.children !== 'string',
|
invariant(typeof item !== 'string', 'A text node cannot be a child of a <View>');
|
||||||
'A text node cannot be a child of a <View>'
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { isInAParentText } = this.context;
|
const { isInAParentText } = this.context;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import normalizeNativeEvent from '..';
|
import normalizeNativeEvent from '..';
|
||||||
|
|
||||||
const normalizeEvent = (nativeEvent) => {
|
const normalizeEvent = nativeEvent => {
|
||||||
const result = normalizeNativeEvent(nativeEvent);
|
const result = normalizeNativeEvent(nativeEvent);
|
||||||
result.timestamp = 1496876171255;
|
result.timestamp = 1496876171255;
|
||||||
if (result.changedTouches && result.changedTouches[0]) {
|
if (result.changedTouches && result.changedTouches[0]) {
|
||||||
@@ -12,7 +12,7 @@ const normalizeEvent = (nativeEvent) => {
|
|||||||
result.touches[0].timestamp = 1496876171255;
|
result.touches[0].timestamp = 1496876171255;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
|
|
||||||
describe('modules/normalizeNativeEvent', () => {
|
describe('modules/normalizeNativeEvent', () => {
|
||||||
describe('mouse events', () => {
|
describe('mouse events', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user