From 0120744e0b0c3eb0216eb2bcf6185b910f2255fe Mon Sep 17 00:00:00 2001 From: wadejs <379664673@qq.com> Date: Fri, 15 Mar 2024 17:35:53 +0800 Subject: [PATCH 1/2] test: add test for Q323 --- questions/323-prop-validation/index.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 questions/323-prop-validation/index.test.ts diff --git a/questions/323-prop-validation/index.test.ts b/questions/323-prop-validation/index.test.ts new file mode 100644 index 0000000..92c5227 --- /dev/null +++ b/questions/323-prop-validation/index.test.ts @@ -0,0 +1,20 @@ +import { mount } from "@vue/test-utils" +import { describe, it, expect } from "vitest" + +import Button from "./Button.vue" + +describe("prop-validation", () => { + it("should have a default type prop of 'default'", () => { + const wrapper = mount(Button) + console.log(wrapper.vm) + expect(wrapper.vm.type).toBe("default") + }) + it("should only accept specific values for the type prop", () => { + const wrapper = mount(Button, { + }) + expect(wrapper.vm.$options.props.type.validator("invalid")).toBe(false) + const validTypes = ["primary", "ghost", "dashed", "link", "text", "default"] + const randomType = validTypes[Math.floor(Math.random() * validTypes.length)] + expect(wrapper.vm.$options.props.type.validator(randomType)).toBe(true) + }) +}) From 21e05bf284f168760e3ef8b827e44cf1cdde28d6 Mon Sep 17 00:00:00 2001 From: wadejs <379664673@qq.com> Date: Fri, 15 Mar 2024 19:59:15 +0800 Subject: [PATCH 2/2] remove console.log --- questions/323-prop-validation/index.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/questions/323-prop-validation/index.test.ts b/questions/323-prop-validation/index.test.ts index 92c5227..ffcc32c 100644 --- a/questions/323-prop-validation/index.test.ts +++ b/questions/323-prop-validation/index.test.ts @@ -6,7 +6,6 @@ import Button from "./Button.vue" describe("prop-validation", () => { it("should have a default type prop of 'default'", () => { const wrapper = mount(Button) - console.log(wrapper.vm) expect(wrapper.vm.type).toBe("default") }) it("should only accept specific values for the type prop", () => {