2019-01-12 11:33:27 +08:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { asyncExpect } from '@/tests/utils';
|
2020-03-07 19:45:13 +08:00
|
|
|
import Radio, { Group, Button } from '..';
|
2019-01-12 11:33:27 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2020-03-07 19:45:13 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2018-06-17 17:25:54 +08:00
|
|
|
|
|
|
|
describe('Radio', () => {
|
2019-01-12 11:33:27 +08:00
|
|
|
focusTest(Radio);
|
2020-03-07 19:45:13 +08:00
|
|
|
mountTest(Radio);
|
|
|
|
mountTest(Group);
|
|
|
|
mountTest(Button);
|
2018-06-17 17:25:54 +08:00
|
|
|
|
|
|
|
it('should render correctly', () => {
|
|
|
|
const wrapper = mount({
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
return <Radio class="customized">Test</Radio>;
|
2018-06-17 17:25:54 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2018-06-17 17:25:54 +08:00
|
|
|
|
|
|
|
it('responses hover events', async () => {
|
2019-01-12 11:33:27 +08:00
|
|
|
const onMouseEnter = jest.fn();
|
|
|
|
const onMouseLeave = jest.fn();
|
2018-06-17 17:25:54 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return <Radio onMouseenter={onMouseEnter} onMouseleave={onMouseLeave} />;
|
|
|
|
},
|
2018-06-17 17:25:54 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
{ sync: false },
|
|
|
|
);
|
2018-06-17 17:25:54 +08:00
|
|
|
await asyncExpect(() => {
|
2019-09-18 20:03:13 +08:00
|
|
|
wrapper.find('label').trigger('mouseenter');
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-06-17 17:25:54 +08:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
expect(onMouseEnter).toHaveBeenCalled();
|
|
|
|
});
|
2019-09-18 20:03:13 +08:00
|
|
|
wrapper.find('label').trigger('mouseleave');
|
2018-06-17 17:25:54 +08:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
expect(onMouseLeave).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|