koel/resources/assets/js/__tests__/services/youtube.spec.ts

31 lines
782 B
TypeScript
Raw Normal View History

2022-04-24 08:50:45 +00:00
import { youtubeService } from '@/services'
2022-04-15 14:24:30 +00:00
import { eventBus } from '@/utils'
import router from '@/router'
import factory from '@/__tests__/factory'
import { mock } from '@/__tests__/__helpers__'
describe('services/youtube', () => {
afterEach(() => {
jest.resetModules()
jest.restoreAllMocks()
jest.clearAllMocks()
})
it('plays a video', () => {
const video = factory<YouTubeVideo>('video', {
id: {
videoId: 'foo'
},
snippet: {
title: 'Bar'
}
})
const emitMock = mock(eventBus, 'emit')
const goMock = mock(router, 'go')
2022-04-24 08:50:45 +00:00
youtubeService.play(video)
2022-04-15 14:24:30 +00:00
expect(emitMock).toHaveBeenCalledWith('PLAY_YOUTUBE_VIDEO', { id: 'foo', title: 'Bar' })
expect(goMock).toHaveBeenCalledWith('youtube')
})
})