Phase 7-8
This commit is contained in:
parent
a196b8f9a8
commit
0148f48204
25 changed files with 2473 additions and 47 deletions
27
web/test/setup.ts
Normal file
27
web/test/setup.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Stub Nuxt auto-imports ที่ composable ใช้ — เบากว่าการลาก @nuxt/test-utils ทั้งชุดเข้ามา
|
||||
* - useState: ตาม semantics ของ Nuxt คือ state แชร์กันตาม key (สร้างครั้งแรก ครั้งถัดไปได้ตัวเดิม)
|
||||
* - computed: ของ vue ตรงๆ
|
||||
* เคลียร์ state ทุก test เพื่อไม่ให้ theme ของ test ก่อนหน้ารั่วมา
|
||||
*/
|
||||
import { beforeEach } from 'vitest'
|
||||
import { computed, ref, type Ref } from 'vue'
|
||||
|
||||
const sharedState = new Map<string, Ref<unknown>>()
|
||||
|
||||
;(globalThis as Record<string, unknown>).useState = <T>(key: string, init: () => T): Ref<T> => {
|
||||
let entry = sharedState.get(key)
|
||||
if (!entry) {
|
||||
entry = ref(init()) as Ref<unknown>
|
||||
sharedState.set(key, entry)
|
||||
}
|
||||
return entry as Ref<T>
|
||||
}
|
||||
|
||||
;(globalThis as Record<string, unknown>).computed = computed
|
||||
|
||||
beforeEach(() => {
|
||||
sharedState.clear()
|
||||
document.documentElement.classList.remove('dark')
|
||||
localStorage.clear()
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue