首页 > 解决方案 > 使用 cypress-axe 测试可访问性

问题描述

cypress-a11y-test在此处输入图像描述我正在尝试将 cypress-axe集成到我的项目中。安装 cypress-axe 和 axe-core 库后。我在cypress\support\index.js中导入了cypress-axe ,如下所示:

// Import commands.js using ES2015 syntax:
import '@cypress/code-coverage/support'
import './commands'
import 'cypress-axe'

Cypress.on('uncaught:exception', () => {
  // returning false here prevents Cypress from
  // failing the test
  return false
})

Cypress.on('window:before:unload', e => {
  const coverage = e.currentTarget.__coverage__;

  if (coverage) {
    map.merge(coverage);
  }
});

在规范文件中,注入 ax 如下:

    before(() => {
        cy.visit(url);
        cy.injectAxe();
    });

    describe('Initial state of component', () => {
        it('Has no detectable a11y violations on load', () => {
            // Test the page at initial load
            cy.checkA11y()
        })
     })

但是当我运行 cypress 测试时,我得到错误cy.injectAxe() is not a function柏树斧头错误

谢谢

标签: accessibilitycypress

解决方案


推荐阅读