From 6858f4e2eab841ec12d173c98a6136d11e2ad69a Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 9 Oct 2018 18:12:02 +0800 Subject: [PATCH] [bugfix] Toast: ssr error (#1910) --- jest.config.js | 4 ++-- packages/address-edit/index.vue | 6 +----- packages/address-edit/test/index.spec.js | 13 +++++++++++++ packages/dialog/index.js | 6 ++++++ packages/image-preview/index.js | 6 ++++++ packages/number-keyboard/index.vue | 5 +++++ packages/toast/index.js | 7 ++++++- 7 files changed, 39 insertions(+), 8 deletions(-) diff --git a/jest.config.js b/jest.config.js index f926c25d5..5946ad9ef 100644 --- a/jest.config.js +++ b/jest.config.js @@ -14,9 +14,9 @@ module.exports = { '!**/vant-css/**', '!**/demo/**', '!**/locale/lang/**', - '!**/waterfall/**', '!**/sku/**', - '!**/lazyload/**' + '!**/waterfall/**', + '!**/icon/config/**' ], collectCoverage: true, coverageReporters: ['html', 'lcov', 'text-summary'], diff --git a/packages/address-edit/index.vue b/packages/address-edit/index.vue index bf1393e0c..e40486506 100644 --- a/packages/address-edit/index.vue +++ b/packages/address-edit/index.vue @@ -69,7 +69,7 @@ - + { data, field, button, + wrapper, errorInfo }; }; @@ -225,3 +226,15 @@ test('delete address', async() => { expect(wrapper.emitted('delete')).toBeTruthy(); expect(wrapper.emitted('cancel-delete')).toBeTruthy(); }); + +test('setAddressDetail method', () => { + const { vm, data } = createComponent(); + vm.setAddressDetail('test'); + expect(data.addressDetail).toEqual('test'); +}); + +test('select area', () => { + const { wrapper, data } = createComponent(); + wrapper.find('.van-picker__confirm').trigger('click'); + expect(data.areaCode).toEqual('110101'); +}); diff --git a/packages/dialog/index.js b/packages/dialog/index.js index 489a59c95..aae1e6d67 100644 --- a/packages/dialog/index.js +++ b/packages/dialog/index.js @@ -1,5 +1,6 @@ import Vue from 'vue'; import VanDialog from './Dialog'; +import { isServer } from '../utils'; let instance; @@ -16,6 +17,11 @@ const initInstance = () => { }; const Dialog = options => { + /* istanbul ignore if */ + if (isServer) { + return Promise.resolve(); + } + return new Promise((resolve, reject) => { if (!instance) { initInstance(); diff --git a/packages/image-preview/index.js b/packages/image-preview/index.js index d3eb01bfa..063c24c96 100644 --- a/packages/image-preview/index.js +++ b/packages/image-preview/index.js @@ -1,5 +1,6 @@ import Vue from 'vue'; import VueImagePreview from './ImagePreview'; +import { isServer } from '../utils'; let instance; @@ -11,6 +12,11 @@ const initInstance = () => { }; const ImagePreview = (images, startPosition) => { + /* istanbul ignore if */ + if (isServer) { + return; + } + if (!instance) { initInstance(); } diff --git a/packages/number-keyboard/index.vue b/packages/number-keyboard/index.vue index 9b04bca19..d2a5a2f21 100644 --- a/packages/number-keyboard/index.vue +++ b/packages/number-keyboard/index.vue @@ -136,6 +136,11 @@ export default create({ methods: { handler(action) { + /* istanbul ignore if */ + if (this.$isServer) { + return; + } + if (action !== this.handlerStatus && this.hideOnClickOutside) { this.handlerStatus = action; document.body[(action ? 'add' : 'remove') + 'EventListener']('touchstart', this.onBlur); diff --git a/packages/toast/index.js b/packages/toast/index.js index 29bf3bdbf..b004aa92b 100644 --- a/packages/toast/index.js +++ b/packages/toast/index.js @@ -1,6 +1,6 @@ import Vue from 'vue'; import VueToast from './Toast'; -import { isObj } from '../utils'; +import { isObj, isServer } from '../utils'; const defaultOptions = { type: 'text', @@ -37,6 +37,11 @@ function transformer(options) { } function Toast(options = {}) { + /* istanbul ignore if */ + if (isServer) { + return; + } + const toast = createInstance(); options = {