test: update modal test

pull/22/head
tangjinzhou 2018-05-18 14:30:17 +08:00
parent 9f08fdb856
commit 6cdc08102f
3 changed files with 35 additions and 13 deletions

View File

@ -1,4 +1,5 @@
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import Vue from 'vue'
import Modal from '..' import Modal from '..'
const ModalTester = { const ModalTester = {
@ -8,10 +9,6 @@ const ModalTester = {
return this.$refs.container return this.$refs.container
}, },
}, },
updated () {
console.log('updated')
},
render () { render () {
const modalProps = { const modalProps = {
props: { props: {
@ -33,18 +30,24 @@ const ModalTester = {
} }
describe('Modal', () => { describe('Modal', () => {
it('render correctly', () => { it('render correctly', (done) => {
const wrapper = mount(ModalTester) const wrapper = mount(
wrapper.setProps({ visible: true })
expect(wrapper.html()).toMatchSnapshot()
const wrapper1 = mount(
{ {
render () { render () {
return <ModalTester visible /> return <ModalTester visible />
}, },
} }
) )
expect(wrapper1.html()).toMatchSnapshot() expect(wrapper.html()).toMatchSnapshot()
// https://github.com/vuejs/vue-test-utils/issues/624
const wrapper1 = mount(ModalTester, {
sync: false,
})
wrapper1.setProps({ visible: true })
Vue.nextTick(() => {
expect(wrapper1.html()).toMatchSnapshot()
done()
})
}) })
it('render without footer', () => { it('render without footer', () => {

View File

@ -2,7 +2,26 @@
exports[`Modal render correctly 1`] = ` exports[`Modal render correctly 1`] = `
<div> <div>
<div></div> <div>
<div>
<div class="ant-modal-mask"></div>
<div tabindex="-1" role="dialog" class="ant-modal-wrap ">
<div role="document" class="ant-modal" style="width: 520px;">
<div class="ant-modal-content">
<button aria-label="Close" class="ant-modal-close"><span class="ant-modal-close-x"></span></button>
<div class="ant-modal-body">Here is content of Modal</div>
<div class="ant-modal-footer">
<div>
<button type="button" class="ant-btn ant-btn-default"><span>Cancel</span></button>
<button type="button" class="ant-btn ant-btn-primary"><span>OK</span></button>
</div>
</div>
</div>
<div tabindex="0" style="width: 0px; height: 0px; overflow: hidden;">sentinel</div>
</div>
</div>
</div>
</div>
<!----> <!---->
</div> </div>
`; `;

View File

@ -1,5 +1,5 @@
import Vue from 'vue' // import Vue from 'vue'
Vue.config.silent = true // Vue.config.silent = true
/* eslint-disable global-require */ /* eslint-disable global-require */
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {