mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 10:20:19 +08:00
[improvement] Button: add test cases (#2870)
This commit is contained in:
parent
ef06d058e6
commit
33e6f2265e
@ -10,3 +10,51 @@ test('loading size', () => {
|
|||||||
});
|
});
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('click event', () => {
|
||||||
|
const onClick = jest.fn();
|
||||||
|
const wrapper = mount(Button, {
|
||||||
|
context: {
|
||||||
|
on: {
|
||||||
|
click: onClick
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.trigger('click');
|
||||||
|
expect(onClick.mock.calls.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('not trigger click event when disabled', () => {
|
||||||
|
const onClick = jest.fn();
|
||||||
|
const wrapper = mount(Button, {
|
||||||
|
propsData: {
|
||||||
|
disabled: true
|
||||||
|
},
|
||||||
|
context: {
|
||||||
|
on: {
|
||||||
|
click: onClick
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.trigger('click');
|
||||||
|
expect(onClick.mock.calls.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('not trigger click event when loading', () => {
|
||||||
|
const onClick = jest.fn();
|
||||||
|
const wrapper = mount(Button, {
|
||||||
|
propsData: {
|
||||||
|
loading: true
|
||||||
|
},
|
||||||
|
context: {
|
||||||
|
on: {
|
||||||
|
click: onClick
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.trigger('click');
|
||||||
|
expect(onClick.mock.calls.length).toEqual(0);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user