Skip to content

Commit

Permalink
fix: update toHaveNoAxeViolations and remove skips (#5955)
Browse files Browse the repository at this point in the history
* fix: update toHaveNoAxeViolations and remove skips

* fix: remove debug line
  • Loading branch information
lee-chase committed Sep 3, 2024
1 parent 0c592d2 commit 694128b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2020, 2020
* Copyright IBM Corp. 2020, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -29,33 +29,22 @@ const defaultOptions = {
},
};

function toHaveNoAxeViolations(node, options = {}) {
return new Promise((resolve) => {
axe.run(
node,
{
...defaultOptions,
...options,
},
(error, result) => {
if (error) {
throw error;
}
async function toHaveNoAxeViolations(node, options = {}) {
const result = await axe.run(node, {
...defaultOptions,
...options,
});

if (result.violations.length > 0) {
resolve({
message: () => formatOutput(result.violations),
pass: false,
});
return;
}
if (result.violations.length > 0) {
return {
message: () => formatOutput(result.violations),
pass: false,
};
}

resolve({
pass: true,
});
}
);
});
return {
pass: true,
};
}

function formatOutput(violations) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2021, 2021
* Copyright IBM Corp. 2021, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -93,17 +93,16 @@ describe(componentName, () => {
expect(screen.getByRole('presentation')).toHaveClass(blockClass);
});

// Currently fails due to https://github.com/carbon-design-system/carbon/issues/14135 regarding focusable button
it.skip('has no accessibility violations when closed', async () => {
it('has no accessibility violations when closed', async () => {
const { container } = renderComponent({ open: false });
expect(container).toBeAccessible(`${componentName} closed`);
expect(container).toHaveNoAxeViolations();
await expect(container).toBeAccessible(`${componentName} closed`);
await expect(container).toHaveNoAxeViolations();
});

it('has no accessibility violations', async () => {
const { container } = renderComponent({ open: true });
expect(container).toBeAccessible(componentName);
expect(container).toHaveNoAxeViolations();
await expect(container).toBeAccessible(componentName);
await expect(container).toHaveNoAxeViolations();
});

it('renders closeIconDescription, title, logo, and version', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2021, 2022
* Copyright IBM Corp. 2021, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -185,8 +185,7 @@ describe(componentName, () => {
window.ResizeObserver = ResizeObserver;
});

// Currently fails due to https://github.com/carbon-design-system/carbon/issues/14135 regarding focusable button
it.skip('has no accessibility violations', async () => {
it('has no accessibility violations', async () => {
const { container } = renderComponent({ ...defaultFullPageProps });

expect(container).toBeAccessible(componentName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2021, 2021
* Copyright IBM Corp. 2021, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -76,17 +76,16 @@ describe(componentName, () => {
expect(screen.getByText(defaultProps.primaryButtonText)).toBeVisible();
});

it.skip('has no accessibility violations when closed', async () => {
// Currently fails due to https://github.com/carbon-design-system/carbon/issues/14135 regarding focusable button
it('has no accessibility violations when closed', async () => {
const { container } = renderComponent({ open: false });
expect(container).toBeAccessible(componentName);
expect(container).toHaveNoAxeViolations();
await expect(container).toBeAccessible(componentName);
await expect(container).toHaveNoAxeViolations();
});

it('has no accessibility violations', async () => {
const { container } = renderComponent();
expect(container).toBeAccessible(componentName);
expect(container).toHaveNoAxeViolations();
await expect(container).toBeAccessible(componentName);
await expect(container).toHaveNoAxeViolations();
});

it(`renders children`, async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2020, 2023
* Copyright IBM Corp. 2020, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -106,8 +106,7 @@ const commonTests = (Ts, name, props, testActions) => {
});
});

// Currently fails due to https://github.com/carbon-design-system/carbon/issues/14135 regarding focusable button
it.skip('has no accessibility violations when closed', async () => {
it('has no accessibility violations when closed', async () => {
const { container } = render(
<Ts {...{ ...props, closeIconDescription, label, title }} />
);
Expand Down

0 comments on commit 694128b

Please sign in to comment.