-
Notifications
You must be signed in to change notification settings - Fork 5
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
Web components - Input: Create unit tests #79
base: al-text-input-alpha
Are you sure you want to change the base?
Changes from 3 commits
61afd87
400950b
32a7244
f3f6b9e
aed6a6e
1083608
e944100
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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]; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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> | ||
<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", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
}) | ||
}) |
There was a problem hiding this comment.
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.