zoukankan      html  css  js  c++  java
  • [React ARIA Testing] Test Accessibility of Rendered React Components with jest-axe

    While not all of accessibility testing of a web application can be automated, much of it can be and quite easily using axe-core and jest-axe. Let’s see how to integrate this with React Testing Library to help catch common accessibility issues.

    import React from 'react'
    import 'jest-axe/extend-expect'
    import { axe } from 'jest-axe'
    import { render } from '@testing-library/react'
    
    function InaccessibleForm() {
      return (
        <form>
          <input placeholder="email" />
        </form>
      )
    }
    
    function AccessibleForm() {
      return (
        <form>
          <label htmlFor="username">Username</label>
          <input id="username" placeholder="username" />
        </form>
      )
    }
    
    test('inaccessible forms fail axe', async () => {
      const { container } = render(<InaccessibleForm />)
      expect(await axe(container)).not.toHaveNoViolations()
    })
    
    test('accessible forms pass axe', async () => {
      const { container } = render(<AccessibleForm />)
      expect(await axe(container)).toHaveNoViolations()
    })
  • 相关阅读:
    Portable Executable 可移植可执行
    汇编跳转指令
    Java中this和super
    Java成员变量和类变量
    EasyUI select
    JAVA虚函数
    感想
    函数
    ueditor
    gitlab简介配置和参数修改
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12810779.html
Copyright © 2011-2022 走看看