Skip to content

Commit 1618755

Browse files
committed
test: update tests. add lazyload test
1 parent 889d798 commit 1618755

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/components/VueImageKit.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ export default {
116116
const { srcset, imageKitPrefix, hash, customTransform, src } = this
117117
118118
return srcset
119+
? srcset
119120
.map(size => `${imageKitPrefix}/${hash}/tr:w-${size}${customTransform
120121
? ',' + customTransform
121122
: ''}/${src} ${size}w`)
122123
.join(', ')
124+
: []
123125
},
124126
getSizes () {
125127
const { sizes, srcset, defaultSize } = this

tests/unit/vue-image-kit.spec.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ describe('When I create the VueImageKit component', () => {
3434
return shallowMount(VueImageKit, { propsData })
3535
}
3636

37-
it('should be a Vue instance', () => {
38-
const wrapper = createComponent(item)
39-
expect(wrapper.find(VueImageKit).isVueInstance()).toBe(true)
40-
})
41-
4237
it('should validate all props', () => {
4338
const consoleLog = console.error
4439
console.error = jest.fn()
@@ -88,6 +83,10 @@ describe('When I create the VueImageKit component', () => {
8883
expect(alt.required).toBeFalsy()
8984
expect(alt.type).toBe(String)
9085
expect(alt.default).toBe('')
86+
const lazyLoad = wrapper.vm.$options.props.lazyLoad
87+
expect(lazyLoad.required).toBeFalsy()
88+
expect(lazyLoad.type).toBe(Boolean)
89+
expect(lazyLoad.default).toBe(true)
9190
const component = wrapper.find('.vue-image-kit')
9291
expect(component.exists()).toBe(true)
9392
console.error = consoleLog
@@ -161,6 +160,17 @@ describe('When I create the VueImageKit component', () => {
161160
expect(main.attributes().sizes).toContain('1366px')
162161
})
163162

163+
it('should not have lazy load', () => {
164+
const wrapper = createComponent({ ...item, lazyLoad: false })
165+
const main = wrapper.find('.vue-image-kit')
166+
expect(main.exists()).toBe(true)
167+
expect(main.classes()).toContain('vue-image-kit--loaded')
168+
const placeholder = wrapper.find('.vue-image-kit__placeholder')
169+
expect(placeholder.exists()).toBe(false)
170+
expect(wrapper.vm.showCanvas).toBe(false)
171+
expect(wrapper.vm.$refs.normalLoad).toBeInstanceOf(HTMLImageElement)
172+
})
173+
164174
it('should have a custom transform', async () => {
165175
// https://imagekit.io/features/advanced-image-manipulation-blur-rotate-crop-background-radius
166176
const customTransform = 'c-at_max,bl-1:r-20,bg-FFCFA1'

0 commit comments

Comments
 (0)