2019-01-12 03:33:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Modal from '..';
|
2020-03-07 11:45:13 +00:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2018-05-18 02:10:17 +00:00
|
|
|
|
|
|
|
const ModalTester = {
|
|
|
|
props: ['footer', 'visible'],
|
|
|
|
methods: {
|
2019-01-12 03:33:27 +00:00
|
|
|
getContainer() {
|
|
|
|
return this.$refs.container;
|
2018-05-18 02:10:17 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2018-05-18 02:10:17 +00:00
|
|
|
const modalProps = {
|
|
|
|
props: {
|
|
|
|
...this.$props,
|
|
|
|
getContainer: this.getContainer,
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-05-18 02:10:17 +00:00
|
|
|
return (
|
|
|
|
<div>
|
2019-01-12 03:33:27 +00:00
|
|
|
<div ref="container" />
|
|
|
|
<Modal {...modalProps}>Here is content of Modal</Modal>
|
2018-05-18 02:10:17 +00:00
|
|
|
</div>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-05-18 02:10:17 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-05-18 02:10:17 +00:00
|
|
|
|
|
|
|
describe('Modal', () => {
|
2020-03-07 11:45:13 +00:00
|
|
|
mountTest(Modal);
|
2019-01-12 03:33:27 +00:00
|
|
|
it('render correctly', done => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <ModalTester visible />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
2018-05-18 06:30:17 +00:00
|
|
|
// https://github.com/vuejs/vue-test-utils/issues/624
|
|
|
|
const wrapper1 = mount(ModalTester, {
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
wrapper1.setProps({ visible: true });
|
2020-03-07 11:45:13 +00:00
|
|
|
setTimeout(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper1.html()).toMatchSnapshot();
|
|
|
|
done();
|
2020-03-07 11:45:13 +00:00
|
|
|
}, 10);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-05-18 02:10:17 +00:00
|
|
|
|
|
|
|
it('render without footer', () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <ModalTester visible footer={null} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|