Instructies voor Cypress Component Testing en JavaScript

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard

Het configureren van je componenttests met Cypress en JavaScript

Not for use with personal data
  1. Installeer op het hoofdniveau van je testmap het @axe-core/watcher pakket en al zijn afhankelijkheden met behulp van npm of je voorkeurspakketmanager (bijvoorbeeld, yarn of pnpm).

    npm install --save-dev @axe-core/watcher
  2. In cypress.config.js, importeer de cypressConfig() functie van het @axe-core/watcher pakket en omhul je configuratie hiermee. Stel de testingTypes array in om het volgende op te nemen component:

    const { defineConfig } = require('cypress');
    const { cypressConfig } = require('@axe-core/watcher/cypress/config');
    
    const ACCESSIBILITY_API_KEY = process.env.ACCESSIBILITY_API_KEY
    const PROJECT_ID = process.env.PROJECT_ID
    
    module.exports = defineConfig(  
      cypressConfig({
        axe: {
          apiKey: ACCESSIBILITY_API_KEY,
          projectId: PROJECT_ID,
          testingTypes: ['component']
        },
        // Your existing Cypress configuration code here
        component: {
          // Your component testing configuration
          
          // For example:
          
          // devServer: {
          //  framework: 'react',
          //  bundler: 'webpack',
          //},
        },
      })
    );

    Zorg ervoor dat u ACCESSIBILITY_API_KEY en PROJECT_ID in uw omgeving instelt op uw persoonlijke API-sleutel (te vinden in uw axe-account, **API-SLEUTELS** tab) en uw project-ID (weergegeven bovenaan deze instructies toen u uw project aanmaakte of beschikbaar op de projectpagina door te kiezen voor **Project configureren** onder **Instellingen**).

  3. In je Cypress-component supportbestand (meestal genoemd cypress/support/component.js), importeer het @axe-core/watcher pakket cypressCommands en roep axeWatcherFlush() aan na elke test:

    require('@axe-core/watcher/cypress/support');
    
    afterEach(() => {
      cy.axeWatcherFlush();
    });
  4. Je bent helemaal klaar. Voer je componenttests uit en controleer je resultaten. Let op: @axe-core/watcher werkt alleen in Chrome voor Testen of Chromium en moet alleen gebruikt worden in Cypress run-modus. Het kan worden gebruikt met --headless=new of --headed (bijvoorbeeld, cypress run --headed --browser=chrome-for-testing --component).