Using a special static property for type detecting (#4673)

Related issue: #4655
pull/4472/merge
Wei Zhu 8 years ago committed by 偏右
parent 1a3ea43ebe
commit 85086f14b6

@ -3,7 +3,7 @@ const eslintrc = {
env: { env: {
browser: true, browser: true,
node: true, node: true,
mocha: true, jasmine: true,
jest: true, jest: true,
es6: true, es6: true,
}, },

@ -89,8 +89,8 @@ export default class Breadcrumb extends React.Component<BreadcrumbProps, any> {
} else if (children) { } else if (children) {
crumbs = React.Children.map(children, (element: any, index) => { crumbs = React.Children.map(children, (element: any, index) => {
warning( warning(
element.type === BreadcrumbItem, element && element.type.__ANT_BREADCRUMB_ITEM,
' `BreadcrumbItem` is required as the wrapper of children element. ' 'Breadcrumb only accetps Breadcrumb.Item as it\'s children'
); );
return cloneElement(element, { return cloneElement(element, {
separator, separator,

@ -8,6 +8,8 @@ export interface BreadcrumbItemProps {
} }
export default class BreadcrumbItem extends React.Component<BreadcrumbItemProps, any> { export default class BreadcrumbItem extends React.Component<BreadcrumbItemProps, any> {
static __ANT_BREADCRUMB_ITEM = true;
static defaultProps = { static defaultProps = {
prefixCls: 'ant-breadcrumb', prefixCls: 'ant-breadcrumb',
separator: '/', separator: '/',

@ -0,0 +1,19 @@
import React from 'react';
import { mount } from 'enzyme';
import Breadcrumb from '../Breadcrumb';
describe('Breadcrumb', () => {
it('warns on non-Breadcrumb.Item children', () => {
const MyCom = () => <div>foo</div>;
spyOn(console, 'error');
mount(
<Breadcrumb>
<MyCom />
</Breadcrumb>
);
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'Breadcrumb only accetps Breadcrumb.Item as it\'s children'
);
});
});
Loading…
Cancel
Save