合计:¥ 0.00
diff --git a/packages/submit-bar/test/index.spec.js b/packages/submit-bar/test/index.spec.js
index 48882b688..5184bfe83 100644
--- a/packages/submit-bar/test/index.spec.js
+++ b/packages/submit-bar/test/index.spec.js
@@ -2,10 +2,30 @@ import SubmitBar from '..';
import { mount } from '../../../test/utils';
test('submit', () => {
+ const submit = jest.fn();
const wrapper = mount(SubmitBar, {
- propsData: {
- price: 0.01,
- disabled: true
+ context: {
+ props: {
+ price: 0.01
+ },
+ on: { submit }
+ }
+ });
+
+ const button = wrapper.find('.van-button');
+ button.trigger('click');
+ expect(submit.mock.calls[0]).toBeTruthy();
+});
+
+test('disable submit', () => {
+ const submit = jest.fn();
+ const wrapper = mount(SubmitBar, {
+ context: {
+ props: {
+ price: 0.01,
+ disabled: true
+ },
+ on: { submit }
}
});
@@ -14,10 +34,5 @@ test('submit', () => {
// disabled
const button = wrapper.find('.van-button');
button.trigger('click');
- expect(wrapper.emitted('submit')).toBeFalsy();
-
- // submit
- wrapper.vm.disabled = false;
- button.trigger('click');
- expect(wrapper.emitted('submit')).toBeTruthy();
+ expect(submit.mock.calls[0]).toBeFalsy();
});
diff --git a/packages/switch-cell/index.js b/packages/switch-cell/index.js
index 770f6cb49..e9e297683 100644
--- a/packages/switch-cell/index.js
+++ b/packages/switch-cell/index.js
@@ -5,34 +5,34 @@ import SwitchMixin from '../mixins/switch';
const [sfc, bem] = use('switch-cell');
-export default sfc({
- mixins: [SwitchMixin],
+export default sfc(
+ {
+ mixins: [SwitchMixin],
- props: {
- title: String,
- border: Boolean,
- size: {
- type: String,
- default: '24px'
+ props: {
+ title: String,
+ border: Boolean,
+ size: {
+ type: String,
+ default: '24px'
+ }
+ },
+
+ render(h, context) {
+ const { props } = context;
+
+ return (
+
+
+ |
+ );
}
},
-
- watch: {
- value() {
- this.$emit('change', this.value);
- }
- },
-
- render(h) {
- return (
-
- {
- this.$emit('input', value);
- }}
- />
- |
- );
- }
-});
+ true
+);
diff --git a/packages/switch-cell/test/index.spec.js b/packages/switch-cell/test/index.spec.js
index ff1f0248a..e48e9b527 100644
--- a/packages/switch-cell/test/index.spec.js
+++ b/packages/switch-cell/test/index.spec.js
@@ -1,13 +1,20 @@
import SwitchCell from '..';
import { mount } from '../../../test/utils';
-test('emit event', () => {
- const wrapper = mount(SwitchCell);
+test('change event', () => {
+ const onChange = jest.fn();
+ const wrapper = mount(SwitchCell, {
+ context: {
+ on: {
+ change: onChange
+ }
+ }
+ });
wrapper.vm.$on('input', value => {
wrapper.setProps({ value });
});
wrapper.find('.van-switch').trigger('click');
- expect(wrapper.emitted('change')).toBeTruthy();
+ expect(onChange.mock.calls[0]).toBeTruthy();
});
diff --git a/packages/tag/index.js b/packages/tag/index.js
index c44dca03e..51d433534 100644
--- a/packages/tag/index.js
+++ b/packages/tag/index.js
@@ -9,51 +9,45 @@ const COLOR_MAP = {
success: GREEN
};
-export default sfc({
- props: {
- size: String,
- type: String,
- mark: Boolean,
- color: String,
- plain: Boolean,
- round: Boolean,
- textColor: String
- },
+export default sfc(
+ {
+ props: {
+ size: String,
+ type: String,
+ mark: Boolean,
+ color: String,
+ plain: Boolean,
+ round: Boolean,
+ textColor: String
+ },
- computed: {
- style() {
- const color = this.color || COLOR_MAP[this.type] || GRAY_DARK;
- const key = this.plain ? 'color' : 'backgroundColor';
+ render(h, context) {
+ const { props } = context;
+ const { mark, plain, round, size } = context.props;
+
+ const color = props.color || COLOR_MAP[props.type] || GRAY_DARK;
+ const key = plain ? 'color' : 'backgroundColor';
const style = { [key]: color };
- if (this.textColor) {
- style.color = this.textColor;
+ if (props.textColor) {
+ style.color = props.textColor;
}
- return style;
+ return (
+
+ {context.children}
+
+ );
}
},
-
- render(h) {
- const {
- mark,
- plain,
- round,
- size
- } = this;
-
- return (
-
- {this.$slots.default}
-
- );
- }
-});
+ true
+);
diff --git a/packages/utils/index.js b/packages/utils/index.js
index 21a5d2ca1..d3c7d3549 100644
--- a/packages/utils/index.js
+++ b/packages/utils/index.js
@@ -4,6 +4,8 @@ export { use, useSlots } from './use';
export const isServer = Vue.prototype.$isServer;
+export function noop() {}
+
export function isDef(value) {
return value !== undefined && value !== null;
}