4 files changed +36
-6
lines changed Original file line number Diff line number Diff line change 42
42
"jest" : " ^27.0.6" ,
43
43
"poi" : " 12.10.3" ,
44
44
"prettier" : " ^2.5.0" ,
45
+ "regenerator-runtime" : " ^0.13.9" ,
45
46
"rollup-plugin-typescript2" : " ^0.31.1" ,
46
47
"typescript" : " ^4.3.4" ,
47
48
"vue" : " ^3.0.5" ,
Original file line number Diff line number Diff line change
1
+ import 'regenerator-runtime/runtime'
1
2
import { mount } from '@vue/test-utils'
3
+
2
4
import ContentLoader from './ContentLoader'
3
5
4
6
describe ( 'ContentLoader' , ( ) => {
@@ -200,4 +202,20 @@ describe('ContentLoader', () => {
200
202
expect ( wrapper . find ( 'svg' ) . classes ( ) ) . toEqual ( [ 'loader' ] )
201
203
expect ( wrapper . find ( 'svg' ) . attributes ( ) ) . toMatchObject ( { id : 'loader' } )
202
204
} )
205
+
206
+ it ( 'updates the computedViewBox when props change' , async ( ) => {
207
+ const wrapper = mount ( ContentLoader , {
208
+ props : {
209
+ viewBox : '0 0 100 100' ,
210
+ } ,
211
+ } )
212
+
213
+ expect ( wrapper . find ( 'svg' ) . attributes ( 'viewBox' ) ) . toBe ( '0 0 100 100' )
214
+
215
+ await wrapper . setProps ( { viewBox : '0 0 200 200' } )
216
+ expect ( wrapper . find ( 'svg' ) . attributes ( 'viewBox' ) ) . toBe ( '0 0 200 200' )
217
+
218
+ await wrapper . setProps ( { viewBox : null , width : 50 , height : 100 } )
219
+ expect ( wrapper . find ( 'svg' ) . attributes ( 'viewBox' ) ) . toBe ( '0 0 50 100' )
220
+ } )
203
221
} )
Original file line number Diff line number Diff line change 1
- import { defineComponent } from 'vue'
1
+ import { defineComponent , computed } from 'vue'
2
2
import uid from './uid'
3
3
4
4
export default defineComponent ( {
@@ -52,11 +52,17 @@ export default defineComponent({
52
52
} ,
53
53
54
54
setup ( props ) {
55
- const idClip = props . uniqueKey ? `${ props . uniqueKey } -idClip` : uid ( )
56
- const idGradient = props . uniqueKey ? `${ props . uniqueKey } -idGradient` : uid ( )
57
- const width = props . width ?? 400
58
- const height = props . height ?? 130
59
- const computedViewBox = props . viewBox ?? `0 0 ${ width } ${ height } `
55
+ const idClip = computed ( ( ) =>
56
+ props . uniqueKey ? `${ props . uniqueKey } -idClip` : uid ( )
57
+ )
58
+ const idGradient = computed ( ( ) =>
59
+ props . uniqueKey ? `${ props . uniqueKey } -idGradient` : uid ( )
60
+ )
61
+ const width = computed ( ( ) => props . width ?? 400 )
62
+ const height = computed ( ( ) => props . height ?? 130 )
63
+ const computedViewBox = computed (
64
+ ( ) => props . viewBox ?? `0 0 ${ width . value } ${ height . value } `
65
+ )
60
66
61
67
return {
62
68
idClip,
Original file line number Diff line number Diff line change @@ -8134,6 +8134,11 @@ regenerator-runtime@^0.13.4:
8134
8134
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55"
8135
8135
integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==
8136
8136
8137
+ regenerator-runtime@^0.13.9 :
8138
+ version "0.13.9"
8139
+ resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"
8140
+ integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==
8141
+
8137
8142
regenerator-transform@^0.14.2 :
8138
8143
version "0.14.5"
8139
8144
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.14.5.tgz#c98da154683671c9c4dcb16ece736517e1b7feb4"
0 commit comments