我有以下代碼:
<div className="button">
<a href={SOME_URL}>
...
...
</a>
</div>
在我的測驗中,如果我嘗試這樣做:
const link = screen.getByRole('link');
我收到以下錯誤:
TestingLibraryElementError: Unable to find an accessible element with the role "link"
運行screen.debug(),我得到以下資訊:
<div
class="button"
>
<a>
那怎么找不到呢?
uj5u.com熱心網友回復:
a[href] 具有鏈接的默認角色...
來源
您需要href在<a>.
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/337241.html
