11import Vue from 'vue' ;
22import ImagePreview from '..' ;
33import ImagePreviewVue from '../ImagePreview' ;
4- import { mount , trigger , triggerDrag , transitionStub } from '../../../test/utils' ;
4+ import { mount , trigger , triggerDrag , transitionStub , later } from '../../../test/utils' ;
55
66transitionStub ( ) ;
77
@@ -64,7 +64,7 @@ test('function call', done => {
6464 } ) ;
6565} ) ;
6666
67- test ( 'function call options' , done => {
67+ test ( 'onClose option' , async done => {
6868 const onClose = jest . fn ( ) ;
6969 const instance = ImagePreview ( {
7070 images,
@@ -75,14 +75,28 @@ test('function call options', done => {
7575 instance . $emit ( 'input' , true ) ;
7676 expect ( onClose ) . toHaveBeenCalledTimes ( 0 ) ;
7777
78- Vue . nextTick ( ( ) => {
79- const wrapper = document . querySelector ( '.van-image-preview' ) ;
80- const swipe = wrapper . querySelector ( '.van-swipe__track' ) ;
81- triggerDrag ( swipe , 0 , 0 ) ;
82- expect ( onClose ) . toHaveBeenCalledTimes ( 1 ) ;
83- expect ( onClose ) . toHaveBeenCalledWith ( { index : 0 , url : 'https://img.yzcdn.cn/1.png' } ) ;
84- done ( ) ;
78+ await later ( ) ;
79+
80+ const wrapper = document . querySelector ( '.van-image-preview' ) ;
81+ const swipe = wrapper . querySelector ( '.van-swipe__track' ) ;
82+ triggerDrag ( swipe , 0 , 0 ) ;
83+ expect ( onClose ) . toHaveBeenCalledTimes ( 1 ) ;
84+ expect ( onClose ) . toHaveBeenCalledWith ( { index : 0 , url : 'https://img.yzcdn.cn/1.png' } ) ;
85+ done ( ) ;
86+ } ) ;
87+
88+ test ( 'onChange option' , async done => {
89+ const instance = ImagePreview ( {
90+ images,
91+ startPostion : 0 ,
92+ onChange ( index ) {
93+ expect ( index ) . toEqual ( 2 ) ;
94+ done ( ) ;
95+ }
8596 } ) ;
97+
98+ const swipe = instance . $el . querySelector ( '.van-swipe__track' ) ;
99+ triggerDrag ( swipe , 1000 , 0 ) ;
86100} ) ;
87101
88102test ( 'register component' , ( ) => {
@@ -137,3 +151,18 @@ test('closeOnPopstate', () => {
137151 trigger ( window , 'popstate' ) ;
138152 expect ( wrapper . emitted ( 'input' ) [ 1 ] ) . toBeFalsy ( ) ;
139153} ) ;
154+
155+ test ( 'lazy-load prop' , ( ) => {
156+ const wrapper = mount ( ImagePreviewVue , {
157+ propsData : {
158+ images,
159+ lazyLoad : true
160+ }
161+ } ) ;
162+
163+ wrapper . setProps ( {
164+ value : true
165+ } ) ;
166+
167+ expect ( wrapper ) . toMatchSnapshot ( ) ;
168+ } ) ;
0 commit comments