Skip to main content

    Running tests

    You can run the following types of tests when building on VA.gov.

    Prerequisite

    Test commands

    Test typeTest allTest oneRequires local build to runTest targetModules used
    Unityarn test:unityarn test:unit ./PATH-TO-TEST-FILEno*.unit.spec.js(x)Mocha, Chai, Sinon, JSDom, Enzyme
    Lintyarn lintyarn lint:js or yarn lint:sassno*.js, *.scssESLint, Prettier, sass-lint
    End to endyarn test:e2eyarn test:e2e ./PATH-TO-TEST-FILEyes*.e2e.spec.jsNightwatch.js
    Accessibilityyarn test:accessibilityyesall pages in sitemap.xmlNightwatch.js

    Requires local build or run

    Some tests require running or building VA.gov:

    • Testing while running watch task: Tests will automatically be run against the site running on that server.
    • Testing with a local build: If nothing is running at http://localhost:3001 (vets-website testing) or, http://localhost:3002 (content-build testing), tests start an Express server and serve the build output in build/localhost.

    Unit tests

    We're moving our docs!

    Find the latest version of this section on the Platform website.

    Still can't find what you're looking for? Reach out to #vfs-platform-support on Slack.

    • Run all Mocha/Chai/Sinon-based unit tests with the file extension .unit.spec.js(x)
    • Use JSDom and Enzyme to test browser and React behavior
    • Are located in test/ directories near the code they're testing in src/

    Linting

    • Verify consistency of JavaScript
    • Enforce code formatting rules
    • Automatically run on git commit as a precommit hook

    Set up your editor to show ESLint errors automatically as you're writing code. This makes the linter far less annoying in day to day use. ESLint has integrations for nearly all popular editors.

    End to end tests

    • Run all Nightwatch.js tests in headless Chrome with the file extension .e2e.spec.js
    • Simulate an actual user completing tasks in the tools and services
    • Are located in test/ directories near the application they're testing in src/

    End to end tests will only pass if they are run against their mock API server. This server is started by the end to end test automatically when vets-api is not running.

    Accessibility tests

    • A variation of e2e tests that run aXe against the content pages running in Chrome.