From a72831b952b835efa556dcfb2b769d0188a12e0a Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Mon, 1 Jun 2020 10:37:32 -0400 Subject: [PATCH] Import jest-axe matchers via setupFilesAfterEnv config property (#8217) * Now expect is extended for jest-axe via the jest setupFilesAfterEnv config property. * Renamed a test setup file for jest. --- app/javascript/onboarding/__tests__/Onboarding.test.jsx | 5 +---- jest.config.js | 1 + testSetup.js | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) create mode 100644 testSetup.js diff --git a/app/javascript/onboarding/__tests__/Onboarding.test.jsx b/app/javascript/onboarding/__tests__/Onboarding.test.jsx index 57d3bfcb5..c34c37eb5 100644 --- a/app/javascript/onboarding/__tests__/Onboarding.test.jsx +++ b/app/javascript/onboarding/__tests__/Onboarding.test.jsx @@ -1,7 +1,7 @@ import { h } from 'preact'; import { deep } from 'preact-render-spy'; import fetch from 'jest-fetch-mock'; -import { axe, toHaveNoViolations } from 'jest-axe'; +import { axe } from 'jest-axe'; import Onboarding from '../Onboarding'; import ProfileForm from '../components/ProfileForm'; @@ -53,9 +53,6 @@ function expectStepperToRender(onboardingSlides, activeDotCount) { } describe('', () => { - beforeAll(() => { - expect.extend(toHaveNoViolations); - }); beforeEach(() => { fetch.resetMocks(); }); diff --git a/jest.config.js b/jest.config.js index 8d7862988..540be60ed 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,6 +6,7 @@ process.env.TZ = 'UTC'; module.exports = { + setupFilesAfterEnv: ['./testSetup.js'], collectCoverageFrom: [ 'app/javascript/**/*.{js,jsx}', // This exclusion avoids running coverage on Barrel files, https://twitter.com/housecor/status/981558704708472832 diff --git a/testSetup.js b/testSetup.js new file mode 100644 index 000000000..dee020c20 --- /dev/null +++ b/testSetup.js @@ -0,0 +1 @@ +import 'jest-axe/extend-expect';