Files
hermes-desktop/tests/client/script-setup-let-assignment.test.ts
T
toor 01d9e301fc
Build / build (push) Canceled after 0s
Playwright / browser (push) Canceled after 0s
initialize Electron desktop app and remove unused files
2026-10-25 01:09:01 +08:00

30 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// @vitest-environment jsdom
import { describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'
import Fixture from './fixtures/script-setup-let-assignment.vue'
/**
* 验证 `<script setup>` 里的 `let` 绑定在模板内联语句里到底能不能写。
*
* known-issues #3 认为「编译只对 ref 做解包,let 绑定在模板内联语句里不可写,
* 这个重置很可能不生效」。这个结论需要运行时证据,不能只靠读编译产物 ——
* compileScript 会为 `setup-let` 绑定生成一对 getter/setter 放进 __returned__,
* 模板里的 `$setup.x = v` 走 setter,会写回闭包变量。
*
* 判据必须有区分度:先把 counter 推到非 0,再内联复位后读取。
* 若复位不生效,读到的是 1;复位生效则读到 0。
*/
describe('script setup let binding assignment', () => {
it('resets the counter before the follow-up call reads it', async () => {
const wrapper = mount(Fixture)
await wrapper.find('.bump').trigger('click')
expect((wrapper.vm as any).observed).toEqual([1])
await wrapper.find('.reset-read').trigger('click')
// 内联赋值先把 counter 置 0,read() 再读到它 —— 读到 0 说明赋值确实生效
expect((wrapper.vm as any).observed).toEqual([1, 0])
})
})