Skip to content

Commit 13edb74

Browse files
committed
test: add test for sync reactivity watcher
1 parent 897829b commit 13edb74

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/vue-i18n-core/test/composer.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,35 @@ describe('locale', () => {
6464
test('reactivity', async () => {
6565
const fn = vi.fn()
6666

67-
const { locale } = createComposer({})
67+
const { locale, t } = createComposer({
68+
messages: {
69+
en: {
70+
test: 'en'
71+
},
72+
'en-US': {
73+
test: 'en-US'
74+
}
75+
}
76+
})
6877
watch(locale, fn)
6978
locale.value = 'en'
7079
await nextTick()
7180

7281
expect(fn).toBeCalled()
7382
expect(fn.mock.calls[0][0]).toEqual('en')
7483
expect(fn.mock.calls[0][1]).toEqual('en-US')
84+
85+
let result = ''
86+
locale.value = 'en'
87+
88+
watch(locale, () => (result = t('test')), {
89+
immediate: true,
90+
flush: 'sync'
91+
})
92+
expect(result).toEqual('en')
93+
locale.value = 'en-US'
94+
await nextTick()
95+
expect(result).toEqual('en-US')
7596
})
7697
})
7798

0 commit comments

Comments
 (0)