简体   繁体   English

在 jest 中测试输入类型文件

[英]test input type file in jest

How i can simply make unit testing for the value of input type file :我如何简单地对输入类型文件的值进行单元测试:

<input required type="file" class="form-control blue-border" accept=".jpg, .jpeg, .png" data-testid="file" /> 

I tryed我试过了

descripe('ex....',()=>{
     test('ex.....',()=>{
     const file=screen.getByTestId('file')
     expect(file.value='myfile.png').toContain(/(\.jpg|\.jpeg|\.png)$/i)
})
})

but i have error : InvalidStateError: This input element accepts a filename, which may only be programmatically set to the empty string.但我有错误:InvalidStateError:此输入元素接受一个文件名,该文件名只能以编程方式设置为空字符串。

尝试这个

expect(file.value).toMatch(/(\.jpg|\.jpeg|\.png)$/i)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM