使用Vue-Utils的单位测试:访问课堂中的元素

发布于 2025-02-12 02:27:14 字数 1874 浏览 1 评论 0原文

我目前正在测试我的视图应用程序。 我似乎无法访问< validation-provider>中的元素。 您知道该怎么做吗?

这是我的前端代码:

<template>
    <div>
        <validation-observer v-slot="{ handleSubmit }" class="flex">
            <div class="flex align-center mr-30">
                <span class="mr-10">{{ $t('time.from') }}</span>

                <validation-provider
                    class="relative"
                    v-slot="{ errors }"
                    :rules="{ requiredObject: true }">

                    <calendar-input
                        class="w-270 mr-10"
                        :class="{
                            error: errors[0]
                        }"
                        color="green"
                        multiple
                        :available-dates="{ start: activeOutlet.outlet_start_date, end: currentPrice.start_date || new Date() }"
                        v-model="date">
                    </calendar-input>

                </validation-provider>
        </validation-observer>
    </div>
</template>

<script src="./addNewPeriodLabelPrice.js"></script>

和我的测试代码:

describe('Unit test AddNewPeriodLabelPrice', () => {

    it("validation-observer should exist", () => {
        const wrapper = mount(AddNewPeriodLabelPrice);
        expect(wrapper.find('validation-observer').exists()).toBe(true);
    })

    it("span should exist", () => {
        const wrapper = mount(AddNewPeriodLabelPrice);
        expect(wrapper.find('#test-span').exists()).toBe(true);
    })
    // Error: expect true but received false

多谢

I am currently testing my view application.
I can't seem to access the elements inside <validation-provider>.
Do you have any idea how to do this?

Here is my frontend code:

<template>
    <div>
        <validation-observer v-slot="{ handleSubmit }" class="flex">
            <div class="flex align-center mr-30">
                <span class="mr-10">{{ $t('time.from') }}</span>

                <validation-provider
                    class="relative"
                    v-slot="{ errors }"
                    :rules="{ requiredObject: true }">

                    <calendar-input
                        class="w-270 mr-10"
                        :class="{
                            error: errors[0]
                        }"
                        color="green"
                        multiple
                        :available-dates="{ start: activeOutlet.outlet_start_date, end: currentPrice.start_date || new Date() }"
                        v-model="date">
                    </calendar-input>

                </validation-provider>
        </validation-observer>
    </div>
</template>

<script src="./addNewPeriodLabelPrice.js"></script>

and my test code:

describe('Unit test AddNewPeriodLabelPrice', () => {

    it("validation-observer should exist", () => {
        const wrapper = mount(AddNewPeriodLabelPrice);
        expect(wrapper.find('validation-observer').exists()).toBe(true);
    })

    it("span should exist", () => {
        const wrapper = mount(AddNewPeriodLabelPrice);
        expect(wrapper.find('#test-span').exists()).toBe(true);
    })
    // Error: expect true but received false

Thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文