[improvement] optimize jest fn called judgement (#3029)

This commit is contained in:
neverland
2019-03-21 18:57:44 +08:00
committed by GitHub
parent 7c4908a2e3
commit 8c051b8e1f
24 changed files with 63 additions and 64 deletions
+10 -10
View File
@@ -7,13 +7,15 @@ test('callback events', () => {
const onCancel = jest.fn();
const onSelect = jest.fn();
const actions = [
{ name: 'Option', callback },
{ name: 'Option', disabled: true }
];
const wrapper = mount(Actionsheet, {
propsData: {
value: true,
actions: [
{ name: 'Option', callback },
{ name: 'Option', disabled: true }
],
actions,
cancelText: 'Cancel'
},
context: {
@@ -30,12 +32,10 @@ test('callback events', () => {
options.at(1).trigger('click');
wrapper.find('.van-actionsheet__cancel').trigger('click');
expect(callback.mock.calls.length).toBe(1);
expect(onCancel.mock.calls.length).toBeTruthy();
expect(onInput.mock.calls[0][0]).toBeFalsy();
expect(onSelect.mock.calls[0][0].name).toEqual('Option');
expect(onSelect.mock.calls[0][1]).toEqual(0);
expect(onSelect.mock.calls[0][1]).toBeFalsy();
expect(callback).toHaveBeenCalled();
expect(onCancel).toHaveBeenCalled();
expect(onInput).toHaveBeenCalledWith(false);
expect(onSelect).toHaveBeenCalledWith(actions[0], 0);
expect(wrapper).toMatchSnapshot();
});