繁体   English   中英

测试库以验证 aria-expanded 值为 false

[英]test-library to verify aria-expanded value as false

一旦打开浮出控件,我有一个组件会按照HTML代码呈现浮出控件。 我想使用 test-library 编写测试,以在单击 flyoutItem 后验证aria-expanded值是否为false 我有什么更好的方法来验证 aria-expanded 吗?

// component
    <body>
      <div>
        <div >
          <button aria-expanded="true" class="btn">
            Flyout button
          </button>
          <div class="flyoutContainer>
            <ul class="flyoutItem" role="listbox" >
              <li aria-selected="false" class="item" role="option" >
                <div class="option" >
                    <span >Data is here</span>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </body>

// test

render(<flyout />);

const item = screen.getByText(/Data is here/, {selector: 'span'});
fireEvent.click(item);

const flyoutButton = screen.getByRole('button', {name: 'Flyout button'});
expect(flyoutButton).toHaveClass('aria-expanded').;
expect(flyoutButton).toHaveAttribute('aria-expanded', 'false')

您可以使用getByRole()选项 expand expanded: false像这样

expect(
    screen.getByRole("button", {
        name: "Flyout button",
        expanded: false,
    })
).toBeInTheDocument();

暂无
暂无

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

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