mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-15 02:40:46 +08:00
test: test update
This commit is contained in:
parent
9910afa7fc
commit
5cf4b14153
@ -13,127 +13,117 @@ const COMMON_CONFIG = {
|
|||||||
|
|
||||||
describe('Button.vue', () => {
|
describe('Button.vue', () => {
|
||||||
it('create', () => {
|
it('create', () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
props: { type: 'primary' },
|
props: { type: 'primary' },
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
const buttonElm = instance.element
|
expect(wrapper.classes()).toContain('el-button--primary')
|
||||||
expect(buttonElm.classList.contains('el-button--primary')).toBeTruthy()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('icon', () => {
|
it('icon', () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
props: { icon: 'el-icon-search' },
|
props: { icon: 'el-icon-search' },
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
const buttonElm = instance.element
|
expect(wrapper.find('.el-icon-search').exists()).toBeTruthy()
|
||||||
expect(buttonElm.querySelector('.el-icon-search')).not.toBeUndefined()
|
|
||||||
})
|
})
|
||||||
it('nativeType', () => {
|
it('nativeType', () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
props: { nativeType: 'submit' },
|
props: { nativeType: 'submit' },
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
const buttonElm = instance.element
|
expect(wrapper.attributes('type')).toBe('submit')
|
||||||
expect(buttonElm.getAttribute('type')).toBe('submit')
|
|
||||||
})
|
})
|
||||||
it('loading', () => {
|
it('loading', () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
props: { loading: true },
|
props: { loading: true },
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
const buttonElm = instance.element
|
expect(wrapper.classes()).toContain('is-loading')
|
||||||
expect(buttonElm.querySelector('.el-icon-search')).not.toBeUndefined()
|
expect(wrapper.find('.el-icon-loading').exists()).toBeTruthy()
|
||||||
expect(buttonElm.classList.contains('is-loading')).toBeTruthy()
|
|
||||||
expect(buttonElm.querySelector('.el-icon-loading')).not.toBeUndefined()
|
|
||||||
})
|
})
|
||||||
it('size', () => {
|
it('size', () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
props: { size: 'medium' },
|
props: { size: 'medium' },
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
const buttonElm = instance.element
|
expect(wrapper.classes()).toContain('el-button--medium')
|
||||||
expect(buttonElm.classList.contains('el-button--medium')).toBeTruthy()
|
|
||||||
})
|
})
|
||||||
it('plain', () => {
|
it('plain', () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
props: { plain: true },
|
props: { plain: true },
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
const buttonElm = instance.element
|
expect(wrapper.classes()).toContain('is-plain')
|
||||||
expect(buttonElm.classList.contains('is-plain')).toBeTruthy()
|
|
||||||
})
|
})
|
||||||
it('round', () => {
|
it('round', () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
props: { round: true },
|
props: { round: true },
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
const buttonElm = instance.element
|
expect(wrapper.classes()).toContain('is-round')
|
||||||
expect(buttonElm.classList.contains('is-round')).toBeTruthy()
|
|
||||||
})
|
})
|
||||||
it('circle', () => {
|
it('circle', () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
props: { circle: true },
|
props: { circle: true },
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
const buttonElm = instance.element
|
expect(wrapper.classes()).toContain('is-circle')
|
||||||
expect(buttonElm.classList.contains('is-circle')).toBeTruthy()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('render text', () => {
|
test('render text', () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
slots: {
|
slots: {
|
||||||
default: AXIOM,
|
default: AXIOM,
|
||||||
},
|
},
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
expect(instance.text()).toEqual(AXIOM)
|
expect(wrapper.text()).toEqual(AXIOM)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('handle click', async () => {
|
test('handle click', async () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
slots: {
|
slots: {
|
||||||
default: AXIOM,
|
default: AXIOM,
|
||||||
},
|
},
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
await instance.trigger('click')
|
await wrapper.trigger('click')
|
||||||
expect(instance.emitted()).toBeDefined()
|
expect(wrapper.emitted()).toBeDefined()
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('handle click inside', async () => {
|
test('handle click inside', async () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
slots: {
|
slots: {
|
||||||
default: '<span class="inner-slot"></span>',
|
default: '<span class="inner-slot"></span>',
|
||||||
},
|
},
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
await (<HTMLElement>instance.element.querySelector('.inner-slot')).click()
|
await (<HTMLElement>wrapper.element.querySelector('.inner-slot')).click()
|
||||||
expect(instance.emitted()).toBeDefined()
|
expect(wrapper.emitted()).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('loading implies disabled', async () => {
|
test('loading implies disabled', async () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
slots: {
|
slots: {
|
||||||
default: AXIOM,
|
default: AXIOM,
|
||||||
},
|
},
|
||||||
props: { loading: true },
|
props: { loading: true },
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
await instance.trigger('click')
|
await wrapper.trigger('click')
|
||||||
expect(instance.emitted('click')).toBeUndefined()
|
expect(wrapper.emitted('click')).toBeUndefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('disabled', async () => {
|
it('disabled', async () => {
|
||||||
const instance = mount(Button, {
|
const wrapper = mount(Button, {
|
||||||
props: { disabled: true },
|
props: { disabled: true },
|
||||||
...COMMON_CONFIG,
|
...COMMON_CONFIG,
|
||||||
})
|
})
|
||||||
const buttonElm = instance.element
|
expect(wrapper.classes()).toContain('is-disabled')
|
||||||
expect(buttonElm.classList.contains('is-disabled')).toBeTruthy()
|
await wrapper.trigger('click')
|
||||||
await instance.trigger('click')
|
expect(wrapper.emitted('click')).toBeUndefined()
|
||||||
expect(instance.emitted('click')).toBeUndefined()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user