diff --git a/package.json b/package.json index 8117573..88c789a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "test": "jest" }, "jest": { + "testEnvironment": "jsdom", "moduleFileExtensions": [ "js", "json", diff --git a/specs/LightBox/LightBox.spec.js b/specs/LightBox/LightBox.spec.js index c18a747..65fb571 100644 --- a/specs/LightBox/LightBox.spec.js +++ b/specs/LightBox/LightBox.spec.js @@ -49,7 +49,7 @@ describe('LightBox', () => { let wrapper beforeEach(() => { - jest.useFakeTimers() + jest.useFakeTimers('legacy') wrapper = mount(LightBox, { propsData: { media: mediaWithNineImages, diff --git a/specs/LightBox/MediaArrayMultipleImages.spec.js b/specs/LightBox/MediaArrayMultipleImages.spec.js index a6e6c42..2e3c7bc 100644 --- a/specs/LightBox/MediaArrayMultipleImages.spec.js +++ b/specs/LightBox/MediaArrayMultipleImages.spec.js @@ -85,7 +85,7 @@ describe('LightBox', () => { let container beforeEach(() => { - jest.useFakeTimers() + jest.useFakeTimers('legacy') container = wrapper.findComponent({ ref: 'container' }).element container.removeEventListener = jest.fn() wrapper.destroy() @@ -100,4 +100,4 @@ describe('LightBox', () => { }) }) }) -}) \ No newline at end of file +}) diff --git a/specs/LightBox/MediaArrayOneImageWithoutType.spec.js b/specs/LightBox/MediaArrayOneImageWithoutType.spec.js index c30ee05..15070d1 100644 --- a/specs/LightBox/MediaArrayOneImageWithoutType.spec.js +++ b/specs/LightBox/MediaArrayOneImageWithoutType.spec.js @@ -64,7 +64,7 @@ describe('LightBox', () => { describe('mouse movement', () => { beforeEach(() => { - jest.useFakeTimers() + jest.useFakeTimers('legacy') }) describe('moving the mouse', () => { @@ -162,4 +162,4 @@ describe('LightBox', () => { }) }) }) -}) \ No newline at end of file +}) diff --git a/specs/LightBox/MediaArrayOneVideoWithAutoplay.spec.js b/specs/LightBox/MediaArrayOneVideoWithAutoplay.spec.js new file mode 100644 index 0000000..c548a0b --- /dev/null +++ b/specs/LightBox/MediaArrayOneVideoWithAutoplay.spec.js @@ -0,0 +1,42 @@ +import { mount } from '@vue/test-utils' +import LightBox from '@/LightBox' + +import { mediaWithOneVideoWithAutoplay } from '../props' + +describe('LightBox', () => { + describe('given one video with autoplay in the media array', () => { + let wrapper + + const pauseStub = jest + .spyOn(window.HTMLMediaElement.prototype, 'pause') + .mockImplementation(() => {}) + const playStub = jest + .spyOn(window.HTMLMediaElement.prototype, 'play') + .mockImplementation(() => {}) + + beforeEach(() => { + wrapper = mount(LightBox, { + propsData: { + media: mediaWithOneVideoWithAutoplay + } + }) + }) + + afterEach(() => { + wrapper.destroy() + }) + + describe('showImage', () => { + test('calls play on the video', () => { + expect(playStub).toHaveBeenCalled() + }) + }) + + describe('closeLightBox', () => { + test('calls pause on the video', async () => { + wrapper.vm.closeLightBox() + expect(pauseStub).toHaveBeenCalledTimes(1) + }) + }) + }) +}) \ No newline at end of file diff --git a/specs/LightBox/MediaArrayOneVideo.spec.js b/specs/LightBox/MediaArrayOneVideoWithoutAutoplay.spec.js similarity index 78% rename from specs/LightBox/MediaArrayOneVideo.spec.js rename to specs/LightBox/MediaArrayOneVideoWithoutAutoplay.spec.js index c5787d0..4a4b1be 100644 --- a/specs/LightBox/MediaArrayOneVideo.spec.js +++ b/specs/LightBox/MediaArrayOneVideoWithoutAutoplay.spec.js @@ -1,16 +1,16 @@ import { mount } from '@vue/test-utils' import LightBox from '@/LightBox' -import { mediaWithOneVideo } from '../props' +import { mediaWithOneVideoWithoutAutoplay } from '../props' describe('LightBox', () => { - describe('given one video in the media array', () => { + describe('given one video without autoplay in the media array', () => { let wrapper beforeEach(() => { wrapper = mount(LightBox, { propsData: { - media: mediaWithOneVideo + media: mediaWithOneVideoWithoutAutoplay } }) }) diff --git a/specs/props.js b/specs/props.js index 071e51d..f7440e4 100644 --- a/specs/props.js +++ b/specs/props.js @@ -13,7 +13,7 @@ const mediaWithOneImageWithType = [ } ] -const mediaWithOneVideo = [ +const mediaWithOneVideoWithoutAutoplay = [ { type: 'video', thumb: 'http://test/test-thumb.jpg', @@ -25,6 +25,19 @@ const mediaWithOneVideo = [ } ] +const mediaWithOneVideoWithAutoplay = [ + { + type: 'video', + thumb: 'http://test/test-thumb.jpg', + autoplay: true, + sources: [ + { + src: 'http://test/test-video.mp4' + } + ] + } +] + const mediaWithOneYoutube = [ { type: 'youtube', @@ -72,4 +85,4 @@ const mediaWithNineImages = [ } ] -export { mediaWithOneImageWithoutType, mediaWithOneImageWithType, mediaWithOneVideo, mediaWithOneYoutube, mediaWithNineImages } +export { mediaWithOneImageWithoutType, mediaWithOneImageWithType, mediaWithOneVideoWithoutAutoplay, mediaWithOneVideoWithAutoplay, mediaWithOneYoutube, mediaWithNineImages }