Skip to content

Instantly share code, notes, and snippets.

@straker
Created March 7, 2022 17:34
Show Gist options
  • Select an option

  • Save straker/f2dc03112bc01b0b3d6f44f6132d0e31 to your computer and use it in GitHub Desktop.

Select an option

Save straker/f2dc03112bc01b0b3d6f44f6132d0e31 to your computer and use it in GitHub Desktop.

Revisions

  1. straker created this gist Mar 7, 2022.
    13 changes: 13 additions & 0 deletions .babelrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    {
    "presets": [
    [
    "@babel/preset-env",
    {
    "targets": {
    "node": "current"
    }
    }
    ],
    "@babel/preset-react"
    ]
    }
    19 changes: 19 additions & 0 deletions index.spec.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    import React from 'react'
    import { render, cleanup } from '@testing-library/react'
    import axe from 'axe-core';
    import assert from 'assert';

    const App = () => <h1>Hello World</h1>

    describe("axe-core, jest, @testing-library/react", () => {
    afterEach(() => {
    cleanup();
    });

    it('should test @testing-library/react component', async () => {
    // @testing-library/react automatically appends the container to the DOM
    const { container } = render(<App />);
    const results = await axe.run(container);
    assert.equal(results.violations.length, 0);
    });
    });
    17 changes: 17 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    {
    "scripts": {
    "test": "jest"
    },
    "devDependencies": {
    "@babel/preset-env": "^7.16.11",
    "@babel/preset-react": "^7.16.7",
    "@testing-library/react": "^12.1.3",
    "axe-core": "^4.4.1",
    "jest": "^27.5.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
    },
    "jest": {
    "testEnvironment": "jsdom"
    }
    }