Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import js from "@eslint/js";
import eslintConfigPrettierRecommended from "eslint-config-prettier";
import vitest from "@vitest/eslint-plugin";

export default [js.configs.recommended, eslintConfigPrettierRecommended];
export default [js.configs.recommended, eslintConfigPrettierRecommended, vitest];
199 changes: 199 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@storybook/theming": "^8.2.9",
"@storybook/web-components": "^8.2.9",
"@storybook/web-components-vite": "^8.2.9",
"@vitest/eslint-plugin": "^1.1.7",
"@vitest/ui": "^1.6.0",
"axe-playwright": "^2.0.2",
"concurrently": "^8.2.2",
Expand Down
36 changes: 36 additions & 0 deletions src/components/usa-text-input/usa-text-input.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { beforeEach, describe, expect, it } from "vitest";

import "./index.js";

function getInsideInput() {
return document.body
.querySelector("usa-text-input")
.shadowRoot;
}

function getLabelContext() {
return getInsideInput().querySelector("label")?.shadowRoot?.getAttribute("for")
}

function getInputElement() {
return getInsideInput().querySelector("input");
}

describe("usa-text-input component", async () => {
beforeEach(async () => {
document.body.innerHTML = `
<usa-text-input>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: For discussion, are there any props we want to support in this custom element?

For example: disabled, error, success, width?

Last three are from USWDS text input variants.

image

<label for="input-type-text">Text input label</label>
<input id="input-type-text" name="input-type-text">
</usa-text-input>
`
});

it("Should show props", () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: This test might only be necessary if we progressively enhance the component.

expect(getInputElement().getAttribute("id")).toContain("input-type-text");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: Might not be necessary if we're not progressively enhancing or doing validation.

})

it("Should have an associated label", () => {
expect(getInputElement().getAttribute("id")).toMatch(getLabelContext());
})
})