Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit e961acc

Browse files
author
Łukasz Florczak
committed
Basic unit tests
1 parent 9b62b1c commit e961acc

File tree

5 files changed

+60
-14
lines changed

5 files changed

+60
-14
lines changed

src/mixins/preparations.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ const mixin = {
4848
* Prepare slides active/current classes
4949
*/
5050
prepareSlidesClasses () {
51+
if (this.currentSlide === null) {
52+
return false
53+
}
54+
5155
// Remove active & current classes
5256
for (let i = 0; i < this.slidesCount; i++) {
5357
this.slides[i].classList.remove('agile__slide--active')
@@ -84,7 +88,7 @@ const mixin = {
8488
if (this.settings.unagile) {
8589
this.translateX = 0
8690
} else {
87-
if (this.currentSlide === null) {
91+
if (this.currentSlide === null && this.slidesCount) {
8892
this.currentSlide = this.settings.initialSlide
8993
}
9094

tests/unit/example.spec.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/unit/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const testsContext = require.context('./specs', true, /\.spec$/)
2+
testsContext.keys().forEach(testsContext)

tests/unit/specs/events.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { expect } from 'chai'
2+
import { shallowMount } from '@vue/test-utils'
3+
import Agile from '@/Agile.vue'
4+
5+
const slides = '<div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div>'
6+
7+
describe('Events emitting:', () => {
8+
describe('@afterChange', () => {
9+
it('should be called after a current slide changes', async () => {
10+
const wrapper = shallowMount(Agile, {
11+
slots: {
12+
default: slides
13+
}
14+
})
15+
16+
const nextButton = wrapper.find({ ref: 'nextButton' })
17+
await nextButton.trigger('click')
18+
19+
expect(wrapper.emitted().afterChange).to.deep.equal([[{ currentSlide: 1 }]])
20+
})
21+
})
22+
23+
describe('@beforeChange', () => {
24+
it('should be called before a current slide changes', () => {
25+
const wrapper = shallowMount(Agile, {
26+
slots: {
27+
default: slides
28+
}
29+
})
30+
31+
const nextButton = wrapper.find({ ref: 'nextButton' })
32+
nextButton.trigger('click')
33+
34+
expect(wrapper.emitted().beforeChange).to.deep.equal([[{ currentSlide: 0, nextSlide: 1 }]])
35+
})
36+
})
37+
})

tests/unit/specs/renders.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from 'chai'
2+
import { shallowMount } from '@vue/test-utils'
3+
import Agile from '@/Agile.vue'
4+
5+
describe('Renders:', () => {
6+
it('should render nav buttons', () => {
7+
const wrapper = shallowMount(Agile, {
8+
slots: {
9+
prevButton: 'prev',
10+
nextButton: 'next'
11+
}
12+
})
13+
expect(wrapper.text()).to.include('prev')
14+
expect(wrapper.text()).to.include('next')
15+
})
16+
})

0 commit comments

Comments
 (0)