mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-04-23 20:10:41 +08: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"', () => {
|
||||
test('text node throws error', () => {
|
||||
const children = 'hello';
|
||||
const render = () => shallow(<View>{children}</View>);
|
||||
test('text node throws error (single)', () => {
|
||||
const render = () => shallow(<View>'hello'</View>);
|
||||
expect(render).toThrow();
|
||||
});
|
||||
|
||||
test('text node throws error (array)', () => {
|
||||
const render = () =>
|
||||
shallow(
|
||||
<View>
|
||||
<View />
|
||||
'hello'
|
||||
<View />
|
||||
</View>
|
||||
);
|
||||
expect(render).toThrow();
|
||||
});
|
||||
|
||||
|
||||
@@ -51,10 +51,9 @@ class View extends Component {
|
||||
} = this.props;
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
invariant(
|
||||
typeof this.props.children !== 'string',
|
||||
'A text node cannot be a child of a <View>'
|
||||
);
|
||||
React.Children.toArray(this.props.children).forEach(item => {
|
||||
invariant(typeof item !== 'string', 'A text node cannot be a child of a <View>');
|
||||
});
|
||||
}
|
||||
|
||||
const { isInAParentText } = this.context;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import normalizeNativeEvent from '..';
|
||||
|
||||
const normalizeEvent = (nativeEvent) => {
|
||||
const normalizeEvent = nativeEvent => {
|
||||
const result = normalizeNativeEvent(nativeEvent);
|
||||
result.timestamp = 1496876171255;
|
||||
if (result.changedTouches && result.changedTouches[0]) {
|
||||
@@ -12,7 +12,7 @@ const normalizeEvent = (nativeEvent) => {
|
||||
result.touches[0].timestamp = 1496876171255;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
describe('modules/normalizeNativeEvent', () => {
|
||||
describe('mouse events', () => {
|
||||
|
||||
Reference in New Issue
Block a user