Skip to content

Commit

Permalink
test(util): improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LoTwT committed Nov 18, 2024
1 parent db8d639 commit 7ae85a4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ describe('copyText', () => {

it('download', () => {
let href = ''
let filename = ''

Reflect.defineProperty(HTMLAnchorElement.prototype, 'href', {
set(v) {
Expand All @@ -277,13 +278,24 @@ it('download', () => {
},
})

Reflect.defineProperty(HTMLAnchorElement.prototype, 'download', {
set(v) {
filename = v
},
get() {
return filename
},
})

URL.createObjectURL = vi.fn(() => 'mock')
URL.revokeObjectURL = vi.fn()
download(new Blob(['hello']), 'test.txt')
expect(href).toBe('mock')
expect(filename).toBe('test.txt')
expect(URL.createObjectURL).toHaveBeenCalled()
expect(URL.revokeObjectURL).toHaveBeenCalled()

download('/a.jpg', 'test.txt')
download('/a.jpg')
expect(href).toBe('/a.jpg')
expect(filename).toBe('file')
})

0 comments on commit 7ae85a4

Please sign in to comment.