Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest-axe integration #301

Closed
wants to merge 1 commit into from
Closed

jest-axe integration #301

wants to merge 1 commit into from

Conversation

mattxwang
Copy link
Member

WIP - see #218

@mattxwang
Copy link
Member Author

@advaithg if you could put this on the backburner for you and the rest of the dev team, that would be great! feel free to restart the PR from scratch if the diff doesn't make sense.

@mattxwang
Copy link
Member Author

Superseded by #412.

@mattxwang mattxwang closed this Jan 28, 2022
@mattxwang mattxwang deleted the jest-axe-integration branch January 28, 2022 01:54
mattxwang added a commit that referenced this pull request Jan 31, 2022
This PR implements the minimum overhead required to run `jest-axe` via GitHub Actions on a set of predefined components. In order, we:

1. install `jest`, `jest-axe`, `@testing-library/react`, `@testing-library/jest-dom`, the minimum set up for a viable test infrastructure
    1. to install `jest`, we add a general `jest.config.js` as a jest configuration file, and `jest.setup.js` as a pre-test setup file (automatically importing our dependencies)
    2. creates a set of mock module mappers for "non-code" webpack elements; a stub file mock (`__mocks__/fileMock.js`) for most files, and the `identity-obj-proxy` to proxy-back CSS/SASS/SCSS class names
    3. adds the `next` preset to babel
    4. adjusts the ESLint config to use the jest environment
2. implements a rudimentary accessibility test in `NewsArticle.test.js`, which is a simple subcomponent with no errors. You can validate this working by adding an arbitrary `<img />` to `NewsArticle.js`; `npm test` will throw an error.
3. implements a rudimentary failing accessibility test in `Footer.test.js`, where an `<ul>` has children that are not `<li>` - showing that negatives work. I then resolve this issue.
4. updates the "Node.JS CI" action to be "Build and Test", and runs `npm test` in it

Ideally, you should be able to add more test files following the configuration in `NewsArticle.test.js`; note the strange `let` pattern with the async version of `act`.

I didn't use the native next testing plugin, since that seems blocked by the upgrade to Next 12 (#409).

Part of #218, supersedes #301.

Relevant reading:

* [Configuring Jest](https://jestjs.io/docs/configuration)
* [`act()` in React](https://reactjs.org/docs/test-utils.html#act)
* [Blog Post: Next.js 11: Setup & Config for Testing, Linting, and Absolute Imports](https://benjaminwfox.medium.com/next-js-setup-config-for-testing-linting-and-absolute-imports-605959d7bd6f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant