-
Notifications
You must be signed in to change notification settings - Fork 174
/
input-field.spec.js
65 lines (50 loc) · 1.58 KB
/
input-field.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { screen } from "@testing-library/vue"
import { describe, expect, it } from "vitest"
import { render } from "~~/test/unit/test-utils/render"
import VInputField from "~/components/VInputField/VInputField.vue"
const props = {
fieldId: "input-id",
labelText: "Label",
size: "medium",
}
describe("VInputField", () => {
it('should render an `input` element with type="text"', async () => {
await render(VInputField, {
attrs: {
placeholder: "Enter some text",
},
props: props,
})
const element = screen.getByPlaceholderText("Enter some text")
expect(element.tagName).toBe("INPUT")
expect(element).toHaveAttribute("type", "text")
})
it("should allow changing the type", async () => {
await render(VInputField, {
attrs: {
placeholder: "Enter some number",
type: "number",
},
props: props,
})
const element = screen.getByPlaceholderText("Enter some number")
expect(element).toHaveAttribute("type", "number")
})
it("should set the ID on the `input` to allow attaching labels", async () => {
await render(VInputField, {
attrs: {
placeholder: "Enter some text",
},
props: props,
})
const element = screen.getByPlaceholderText("Enter some text")
expect(element).toHaveAttribute("id", "input-id")
})
it("should render the label text connected to the input field if specified", async () => {
await render(VInputField, {
props: props,
})
const element = screen.getByLabelText("Label")
expect(element.tagName).toBe("INPUT")
})
})