fix(test): AlbumTrackList tests

This commit is contained in:
Phan An 2022-07-10 11:38:19 +02:00
parent 7f81f3e6c7
commit 179ec0a049
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC

View file

@ -2,23 +2,25 @@ import factory from '@/__tests__/factory'
import { expect, it } from 'vitest' import { expect, it } from 'vitest'
import UnitTestCase from '@/__tests__/UnitTestCase' import UnitTestCase from '@/__tests__/UnitTestCase'
import AlbumTrackList from './AlbumTrackList.vue' import AlbumTrackList from './AlbumTrackList.vue'
import TrackListItem from './AlbumTrackListItem.vue' import { songStore } from '@/stores'
new class extends UnitTestCase { new class extends UnitTestCase {
protected test () { protected test () {
it('lists the correct number of tracks', () => { it('displays the tracks', async () => {
const album = factory<Album>('album')
const fetchMock = this.mock(songStore, 'fetchForAlbum').mockResolvedValue(factory<Song[]>('song', 5))
const { queryAllByTestId } = this.render(AlbumTrackList, { const { queryAllByTestId } = this.render(AlbumTrackList, {
props: { props: {
album: factory<Album>('album') album,
}, tracks: factory<AlbumTrack[]>('album-track', 3)
global: {
stubs: {
TrackListItem
}
} }
}) })
expect(queryAllByTestId('album-track-item')).toHaveLength(2) await this.tick()
expect(fetchMock).toHaveBeenCalledWith(album)
expect(queryAllByTestId('album-track-item')).toHaveLength(3)
}) })
} }
} }