Skip to content

Commit

Permalink
test: add unit test for validation player store (#2)
Browse files Browse the repository at this point in the history
* add a store ut

* move store.spec.ts test file

* merge main

* Remove HelloWorld.spec.ts test file

---------

Co-authored-by: Kai Ceng <[email protected]>
  • Loading branch information
izkizk8 and Kai Ceng committed Apr 8, 2024
1 parent 52bf7f7 commit 8208a3c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/stores/__test__/store.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { setActivePinia, createPinia, storeToRefs } from 'pinia'
import { describe, it, expect, beforeEach } from 'vitest'
import { useCounterStore } from '~/stores/counter'
import { usePlayerStore } from '~/stores/player'

describe('Store', () => {
beforeEach(() => {
setActivePinia(createPinia())
})

it('count', () => {
const counter = useCounterStore()
expect(counter.count).toBe(0)
counter.increment()
expect(counter.count).toBe(1)
expect(counter.doubleCount).toBe(2)
})

it('player', () => {
const player = usePlayerStore()

expect(player.playStatus).toBe(false)
player.togglePlay()
expect(player.playStatus).toBe(true)

expect(player.playList).toEqual([])
expect(player.trackCount).toBe(0)

const { playList, trackCount } = storeToRefs(player)
playList.value.push('song1')
expect(player.playList).toEqual(['song1'])
expect(trackCount.value).toBe(1)
})
})

0 comments on commit 8208a3c

Please sign in to comment.