From bb6839f04f630368cbd2a192b1f417014ef89a5f Mon Sep 17 00:00:00 2001 From: Yanming Deng Date: Tue, 31 Aug 2021 11:36:30 +0800 Subject: [PATCH] test(carousel): remove useless nextTick (#970) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test(carousel): added autoplay and interval test * 写法简化 * use sleep * remove nextTick --- src/carousel/tests/Carousel.spec.ts | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/carousel/tests/Carousel.spec.ts b/src/carousel/tests/Carousel.spec.ts index 8ec4d7f61..8d42e5511 100644 --- a/src/carousel/tests/Carousel.spec.ts +++ b/src/carousel/tests/Carousel.spec.ts @@ -7,6 +7,47 @@ describe('n-carousel', () => { it('should work with import on demand', () => { mount(NCarousel) }) + + it('should work with `autoplay` and `interval` prop', async () => { + const wrapper = mount(NCarousel, { + slots: { + default: () => { + return [...Array(3).keys()].map((i) => { + return h('div', {}, i.toString()) + }) + } + } + }) + + await wrapper.setProps({ autoplay: true, interval: 50 }) + + await sleep(10) + ;([0, 1, 2, 3, 4] as const).forEach((i) => { + if (i === 1) { + expect( + wrapper.find(`[data-index="${i}"]`).attributes('aria-hidden') + ).toBe('false') + } else { + expect( + wrapper.find(`[data-index="${i}"]`).attributes('aria-hidden') + ).toBe('true') + } + }) + + await sleep(60) + ;([0, 1, 2, 3, 4] as const).forEach((i) => { + if (i === 2) { + expect( + wrapper.find(`[data-index="${i}"]`).attributes('aria-hidden') + ).toBe('false') + } else { + expect( + wrapper.find(`[data-index="${i}"]`).attributes('aria-hidden') + ).toBe('true') + } + }) + }) + it('should work with `dotPlacement` prop', async () => { const wrapper = mount(NCarousel)