Skip to content

Commit de59402

Browse files
committed
test: update tests for vueuse
1 parent 4a27f3b commit de59402

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

test/nuxt/composables/use-install-command.spec.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,36 +261,33 @@ describe('useInstallCommand', () => {
261261

262262
describe('copyInstallCommand', () => {
263263
it('should copy command to clipboard and set copied state', async () => {
264-
const writeText = vi.fn().mockResolvedValue(undefined)
265-
vi.stubGlobal('navigator', { clipboard: { writeText } })
266-
267264
const { copyInstallCommand, copied, fullInstallCommand } = useInstallCommand(
268265
'vue',
269266
null,
270267
null,
271268
null,
272269
)
273270

271+
expect(fullInstallCommand.value).toBe('npm install vue')
274272
expect(copied.value).toBe(false)
273+
275274
await copyInstallCommand()
276275

277-
expect(writeText).toHaveBeenCalledWith(fullInstallCommand.value)
276+
// useClipboard sets copied to true after successful copy
278277
expect(copied.value).toBe(true)
279278

280-
// Wait for the timeout to reset copied
279+
// Wait for the timeout to reset copied (copiedDuring: 2000)
281280
await new Promise(resolve => setTimeout(resolve, 2100))
282281
expect(copied.value).toBe(false)
283282
})
284283

285284
it('should not copy when command is empty', async () => {
286-
const writeText = vi.fn().mockResolvedValue(undefined)
287-
vi.stubGlobal('navigator', { clipboard: { writeText } })
288-
289285
const { copyInstallCommand, copied } = useInstallCommand(null, null, null, null)
290286

287+
expect(copied.value).toBe(false)
291288
await copyInstallCommand()
292289

293-
expect(writeText).not.toHaveBeenCalled()
290+
// Should remain false since there was nothing to copy
294291
expect(copied.value).toBe(false)
295292
})
296293
})

0 commit comments

Comments
 (0)