Skip to content

Commit

Permalink
Fixes to make jest 27 work and spec file updates
Browse files Browse the repository at this point in the history
  • Loading branch information
janosrusiczki committed Jun 25, 2021
1 parent 0e38285 commit cd16a94
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"test": "jest"
},
"jest": {
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
Expand Down
2 changes: 1 addition & 1 deletion specs/LightBox/LightBox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('LightBox', () => {
let wrapper

beforeEach(() => {
jest.useFakeTimers()
jest.useFakeTimers('legacy')
wrapper = mount(LightBox, {
propsData: {
media: mediaWithNineImages,
Expand Down
4 changes: 2 additions & 2 deletions specs/LightBox/MediaArrayMultipleImages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -100,4 +100,4 @@ describe('LightBox', () => {
})
})
})
})
})
4 changes: 2 additions & 2 deletions specs/LightBox/MediaArrayOneImageWithoutType.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('LightBox', () => {

describe('mouse movement', () => {
beforeEach(() => {
jest.useFakeTimers()
jest.useFakeTimers('legacy')
})

describe('moving the mouse', () => {
Expand Down Expand Up @@ -162,4 +162,4 @@ describe('LightBox', () => {
})
})
})
})
})
42 changes: 42 additions & 0 deletions specs/LightBox/MediaArrayOneVideoWithAutoplay.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
})
Original file line number Diff line number Diff line change
@@ -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
}
})
})
Expand Down
17 changes: 15 additions & 2 deletions specs/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const mediaWithOneImageWithType = [
}
]

const mediaWithOneVideo = [
const mediaWithOneVideoWithoutAutoplay = [
{
type: 'video',
thumb: 'http://test/test-thumb.jpg',
Expand All @@ -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',
Expand Down Expand Up @@ -72,4 +85,4 @@ const mediaWithNineImages = [
}
]

export { mediaWithOneImageWithoutType, mediaWithOneImageWithType, mediaWithOneVideo, mediaWithOneYoutube, mediaWithNineImages }
export { mediaWithOneImageWithoutType, mediaWithOneImageWithType, mediaWithOneVideoWithoutAutoplay, mediaWithOneVideoWithAutoplay, mediaWithOneYoutube, mediaWithNineImages }

0 comments on commit cd16a94

Please sign in to comment.