Skip to content

Commit

Permalink
auto-id: test valid a11y IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Chance Strickland committed Mar 10, 2020
1 parent 071daa0 commit af73b7b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/auto-id/__tests__/auto-id.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React from "react";
import { useId as mockedId } from "@reach/auto-id";
import { axe } from "jest-axe";
import { render } from "$test/utils";

const { useId } = jest.requireActual("@reach/auto-id");

describe("useId", () => {
it("should generate an incremented ID value", () => {
it("should provide a valid ID for a11y", async () => {
let { container } = render(<TestInput />);
let results = await axe(container);
expect(results).toHaveNoViolations();
});

it("should generate a unique ID value", () => {
function Comp() {
const justNull = null;
const randId = useId(justNull);
Expand All @@ -31,3 +37,13 @@ describe("useId", () => {
expect(getByText("Ok").id).toEqual("awesome");
});
});

function TestInput() {
let id = `name-${useId()}`;
return (
<div>
<label htmlFor={id}>Name</label>
<input name="name" id={id} type="text" />
</div>
);
}

0 comments on commit af73b7b

Please sign in to comment.