Browse Source

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

Related issue: #4655
pull/4472/merge
Wei Zhu 8 years ago
committed by 偏右
parent
commit
85086f14b6
  1. 2
      .eslintrc.js
  2. 4
      components/breadcrumb/Breadcrumb.tsx
  3. 2
      components/breadcrumb/BreadcrumbItem.tsx
  4. 19
      components/breadcrumb/__tests__/Breadcrumb.test.js

2
.eslintrc.js

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

4
components/breadcrumb/Breadcrumb.tsx

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

2
components/breadcrumb/BreadcrumbItem.tsx

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

19
components/breadcrumb/__tests__/Breadcrumb.test.js

@ -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