Skip to content

Commit

Permalink
test(ui/uploader): fix mock fileReader to class
Browse files Browse the repository at this point in the history
affects: @varlet/ui
  • Loading branch information
haoziqaq committed Jul 31, 2021
1 parent 823942b commit f8ce7ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/varlet-ui/src/uploader/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ test('test uploader preview', async () => {
})

await wrapper.vm.handleChange(createEvent('cat.jpg'))
await delay(16)
await wrapper.find('.var-uploader__file').trigger('click')
await delay(16)

Expand Down
21 changes: 12 additions & 9 deletions packages/varlet-ui/src/utils/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,19 @@ interface MockFileReaderCtx {
export function mockFileReader(url: string) {
const originMethod = window.FileReader

Object.assign(window, {
FileReader(this: MockFileReaderCtx) {
this.onload = function () {}
this.result = ''
class FileReader {
result = ''

this.readAsDataURL = function () {
this.result = url
this.onload()
}
},
onload() {}

readAsDataURL() {
this.result = url
this.onload()
}
}

Object.assign(window, {
FileReader,
})

return {
Expand Down

0 comments on commit f8ce7ac

Please sign in to comment.