Skip to content

Commit

Permalink
feat(carousel): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
doom-9 committed Jul 9, 2021
1 parent 4c3299a commit 16353b2
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/carousel/tests/Carousel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { h, nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import { NCarousel } from '../index'
import { sleep } from 'seemly'

describe('n-carousel', () => {
it('should work with import on demand', () => {
Expand Down Expand Up @@ -43,4 +45,47 @@ describe('n-carousel', () => {
}
}
})

it('arrow button should work', async () => {
const wrapper = mount(NCarousel, {
slots: {
default: () => {
return [
h('img', {
style: 'width: 100%; height: 240px; object-fit: cover;',
src: 'https://s.anw.red/news/1623152423.jpg!/both/800x450/quality/78/progressive/true/ignore-error/true'
}),
h('img', {
style: 'width: 100%; height: 240px; object-fit: cover;',
src: 'https://s.anw.red/news/1623152423.jpg!/both/800x450/quality/78/progressive/true/ignore-error/true'
})
]
}
}
})

await wrapper.setProps({
showArrow: true
})

const slidesDOMArray = wrapper.find('.n-carousel__slides').findAll('div')

expect(slidesDOMArray[1].attributes('aria-hidden')).toBe('false')

wrapper
.find('.n-carousel__arrow--right')
.trigger('click')
.then(async () => {
expect(slidesDOMArray[2].attributes('aria-hidden')).toBe('false')
await sleep(1000)
nextTick(() => {
wrapper
.find('.n-carousel__arrow--left')
.trigger('click')
.then(() => {
expect(slidesDOMArray[1].attributes('aria-hidden')).toBe('false')
})
})
})
})
})

0 comments on commit 16353b2

Please sign in to comment.