Skip to content

Commit

Permalink
feat(autoplay): Introduce event that fires on each autoplay change
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrzejchalubek committed Jul 7, 2019
1 parent d021201 commit c0db6ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/autoplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export default function (Glide, Components, Events) {
Components.Run.make('>')

this.start()

Events.emit('autoplay')
}, this.time)
}
}
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ describe("Event's callbacks on", () => {
})
})

test('`autoplay` should be called on each autoplay slide change', (done) => {
const glide = new Glide('#glide', { autoplay: 50 })

let autoplayCallback = jest.fn()

glide.on('autoplay', autoplayCallback)

glide.mount()

expect(autoplayCallback).not.toBeCalled()
setTimeout(() => {
expect(autoplayCallback).toHaveBeenCalledTimes(2)

done()
}, 110)
})

test('`translate.jump` should be called when making a loop change', (done) => {
const glide = new Glide('#glide', { type: 'carousel' })

Expand Down

0 comments on commit c0db6ab

Please sign in to comment.