import Button from '../index'
import Icon from '../../icon'
import { mount } from '@vue/test-utils'
import { renderToString } from '@vue/server-test-utils'
import Vue from 'vue'
describe('Button', () => {
it('renders correctly', () => {
const wrapper = renderToString({
render () {
return
},
})
expect(wrapper).toMatchSnapshot()
})
it('create primary button', () => {
const wrapper = mount({
render (h) {
return
},
})
expect(wrapper.contains('.ant-btn-primary')).toBe(true)
})
it('renders Chinese characters correctly', (done) => {
const wrapper = mount(
{
render (h) {
return
},
}
)
expect(wrapper.text()).toBe('按 钮')
const wrapper1 = renderToString(
{
render (h) {
return
},
}
)
expect(wrapper1).toMatchSnapshot()
const wrapper2 = renderToString(
{
render (h) {
return
},
}
)
expect(wrapper2).toMatchSnapshot()
const wrapper3 = mount(
{
render (h) {
return
},
}
)
Vue.nextTick(() => {
expect(wrapper3.find('.ant-btn').contains('.ant-btn-two-chinese-chars')).toBe(true)
done()
})
})
it('should change loading state instantly by default', () => {
const DefaultButton = {
data () {
return {
loading: false,
}
},
methods: {
enterLoading () {
this.loading = true
},
},
render () {
return
},
}
const wrapper = mount(DefaultButton)
wrapper.trigger('click')
Vue.nextTick(() => {
expect(wrapper.findAll('.ant-btn-loading').length).toBe(1)
})
})
it('should change loading state with delay', (done) => {
const DefaultButton = {
data () {
return {
loading: false,
}
},
methods: {
enterLoading () {
this.loading = { delay: 1000 }
},
},
render () {
return
},
}
const wrapper = mount(DefaultButton)
wrapper.trigger('click')
Vue.nextTick(() => {
expect(wrapper.contains('.ant-btn-loading')).toBe(false)
done()
})
})
it('should support link button', () => {
const wrapper = mount({
render (h) {
return
},
})
expect(wrapper.html()).toMatchSnapshot()
})
it('fixbug renders {0} , 0 and {false}', () => {
const wrapper = mount({
render (h) {
return
},
})
expect(wrapper.html()).toMatchSnapshot()
const wrapper1 = mount({
render (h) {
return
},
})
expect(wrapper1.html()).toMatchSnapshot()
const wrapper2 = mount({
render (h) {
return
},
})
expect(wrapper2.html()).toMatchSnapshot()
})
})