Instructies voor Cypress Component Testen en TypeScript

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

Je componenttests configureren met Cypress en TypeScript

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.ts, importeer de cypressConfig() functie vanuit het @axe-core/watcher pakket en omhul je configuratie ermee. Stel de testingTypes array in om het volgende te bevatten component:

    import { defineConfig } from 'cypress';
    import { cypressConfig } from '@axe-core/watcher/cypress/config';
    
    const ACCESSIBILITY_API_KEY = process.env.ACCESSIBILITY_API_KEY
    const PROJECT_ID = process.env.PROJECT_ID
    
    export default 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 ondersteuning bestand (meestal genoemd cypress/support/component.ts), importeer @axe-core/watcher/cypress/support en roep axeWatcherFlush() aan na elke test:

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