Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Apr 26, 2018
1 parent 537a9d6 commit 0e2b180
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/MenuItem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from 'react';
import { mount, shallow } from 'enzyme';
import KeyCode from 'rc-util/lib/KeyCode';
import Menu, { MenuItem } from '../src';
import Menu, { MenuItem, MenuItemGroup, SubMenu } from '../src';

import { MenuItem as NakedMenuItem } from '../src/MenuItem';

Expand Down Expand Up @@ -81,4 +81,35 @@ describe('MenuItem', () => {
expect(onMouseLeave).toHaveBeenCalledWith({ key, domEvent });
});
});

describe('rest props', () => {
it('can render all props to sub component', () => {
const onClick = jest.fn();
const restProps = {
onClick,
'data-whatever': 'whatever',
title: 'title',
className: 'className',
style: { fontSize: 20 },
};
const wrapper = mount(
<Menu mode="inline" activeKey="1">
<MenuItem key="1" {...restProps}>1</MenuItem>
<SubMenu {...restProps}>
<MenuItem key="2" {...restProps}>3</MenuItem>
</SubMenu>
<MenuItemGroup {...restProps}>
<MenuItem key="3" {...restProps}>4</MenuItem>
</MenuItemGroup>
</Menu>
);
expect(wrapper.render()).toMatchSnapshot();
wrapper.find('MenuItem').at(0).simulate('click');
expect(onClick).toHaveBeenCalledTimes(1);
wrapper.find('SubMenu').at(0).simulate('click');
expect(onClick).toHaveBeenCalledTimes(2);
wrapper.find('MenuItemGroup').at(0).simulate('click');
expect(onClick).toHaveBeenCalledTimes(3);
});
});
});
67 changes: 67 additions & 0 deletions tests/__snapshots__/MenuItem.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MenuItem rest props can render all props to sub component 1`] = `
<ul
aria-activedescendant=""
class="rc-menu rc-menu-root rc-menu-inline"
role="menu"
tabindex="0"
>
<li
aria-selected="false"
class="rc-menu-item className rc-menu-item-active"
data-whatever="whatever"
role="menuitem"
style="font-size: 20px; padding-left: 24px;"
title="title"
>
1
</li>
<li
class="rc-menu-submenu rc-menu-submenu-inline className"
data-whatever="whatever"
style="font-size: 20px;"
>
<div
aria-expanded="false"
aria-haspopup="true"
aria-owns="item_1$Menu"
class="rc-menu-submenu-title"
style="padding-left: 24px;"
title="title"
>
title
<i
class="rc-menu-submenu-arrow"
/>
</div>
<div />
</li>
<li
class="className rc-menu-item-group"
data-whatever="whatever"
style="font-size: 20px;"
>
<div
class="rc-menu-item-group-title"
title="title"
>
title
</div>
<ul
class="rc-menu-item-group-list"
>
<li
aria-selected="false"
class="rc-menu-item className"
data-whatever="whatever"
role="menuitem"
style="font-size: 20px; padding-left: 24px;"
title="title"
>
4
</li>
</ul>
</li>
</ul>
`;

0 comments on commit 0e2b180

Please sign in to comment.