vant/packages/submit-bar/test/index.spec.js

88 lines
1.5 KiB
JavaScript

import SubmitBar from '..';
import { mount } from '../../../test/utils';
test('submit event', () => {
const submit = jest.fn();
const wrapper = mount(SubmitBar, {
context: {
props: {
price: 1
},
on: { submit }
}
});
const button = wrapper.find('.van-button');
button.trigger('click');
expect(submit).toHaveBeenCalled();
});
test('disable submit', () => {
const submit = jest.fn();
const wrapper = mount(SubmitBar, {
context: {
props: {
price: 1,
disabled: true
},
on: { submit }
}
});
expect(wrapper).toMatchSnapshot();
// disabled
const button = wrapper.find('.van-button');
button.trigger('click');
expect(submit).toHaveBeenCalledTimes(0);
});
test('without price', () => {
const wrapper = mount(SubmitBar, {
context: {
props: {
label: 'Label'
}
}
});
expect(wrapper).toMatchSnapshot();
});
test('top slot', () => {
const wrapper = mount(SubmitBar, {
scopedSlots: {
top: () => 'top'
}
});
expect(wrapper).toMatchSnapshot();
});
test('decimal-length prop', () => {
const wrapper = mount(SubmitBar, {
context: {
props: {
price: 111,
decimalLength: 1
}
}
});
expect(wrapper).toMatchSnapshot();
});
test('suffix-label prop', () => {
const wrapper = mount(SubmitBar, {
context: {
props: {
price: 111,
label: 'Label',
suffixLabel: 'Suffix Label'
}
}
});
expect(wrapper).toMatchSnapshot();
});