摩卡柴通过ID获取元素

时间:2019-11-20 15:58:49

标签: vuejs2 mocha chai

这是我的vue.js 2.0 Mocha Chai测试单元,我无法通过ID获取元素,也许您有解决方案?我需要测试输入字段是否正确显示...:

    import { expect } from "chai";
    import { shallowMount } from "@vue/test-utils";
    import Register from "@/components/Register.vue";

    const wrapper = shallowMount(Register);

    describe("Register tests", () => {

       it("Should display an Email input", () => {
        expect(wrapper.vm.$el.querySelector("input[type='email']") !==null).to.be.true
        });// IT WORKS

        it("Should display a name input", () => {
            expect(wrapper.vm.$el.getElementById('name') !== null).to.be.true
        }); 

    });

这是错误:

 1) Register tests
       Should display a name input:
     TypeError: wrapper.vm.$el.getElementById is not a function
      at Context.it (dist\js\webpack:\tests\unit\register.spec.js:26:1)

这是我要测试的元素。 ;

<input type="text" class="form-control form-control-user" min="1"  v-model="user.name" name="name" value ="name" id="name" placeholder="name">

0 个答案:

没有答案