[improvement] CouponCell: functional (#2759)

This commit is contained in:
neverland
2019-02-16 11:39:26 +08:00
committed by GitHub
parent f6ab03fa7e
commit 2ad525c45d
3 changed files with 74 additions and 68 deletions
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`coupon cell 1`] = `
exports[`render coupon cell 1`] = `
<div class="van-cell van-cell--clickable van-coupon-cell">
<div class="van-cell__title"><span>优惠券</span></div>
<div class="van-cell__value"><span>使用优惠</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
@@ -8,10 +8,10 @@ exports[`coupon cell 1`] = `
</div>
`;
exports[`coupon cell 2`] = `
exports[`render coupon cell with coupon 1`] = `
<div class="van-cell van-cell--clickable van-coupon-cell">
<div class="van-cell__title"><span>优惠券</span></div>
<div class="van-cell__value van-coupon-cell--selected"><span>-¥1.00</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
<div class="van-cell__value"><span>-¥1.00</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
<!----></i>
</div>
`;
+15 -9
View File
@@ -109,21 +109,27 @@ test('exchange coupon', () => {
expect(wrapper.emitted('input')[2][0]).toBe('2');
});
test('coupon cell', () => {
test('render coupon cell', () => {
const onClick = jest.fn();
const wrapper = mount(CouponCell, {
listeners: {
click: onClick
context: {
on: {
click: onClick
}
}
});
expect(wrapper).toMatchSnapshot();
wrapper.setProps({
coupons: [{ value: 100 }],
chosenCoupon: 0
});
expect(wrapper).toMatchSnapshot();
wrapper.trigger('click');
expect(onClick.mock.calls.length).toEqual(1);
});
test('render coupon cell with coupon', () => {
const wrapper = mount(CouponCell, {
propsData: {
coupons: [{ value: 100 }],
chosenCoupon: 0
}
});
expect(wrapper).toMatchSnapshot();
});