0

This is my vue.js 2.0 Mocha Chai testing unit, I can't get an element by Id, maybe you have a solution ? I need to test if the input field gets correctly displayed ... :

    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
        }); 

    });

This is the error :

 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)

This is the element that I want to test. ;

<input type="text" class="form-control form-control-user" min="1"  v-model="user.name" name="name" value ="name" id="name" placeholder="name">
harmonius cool
  • 337
  • 1
  • 2
  • 23
  • 1
    Can you share the html source where you are trying `getElementById` ? – stud3nt Nov 20 '19 at 16:14
  • Not directly related to your asked, but you should probably use `to.not.be.null` instead of `!== null).to.be.true`. see https://stackoverflow.com/questions/29464849/how-to-assert-not-null – ConorSheehan1 Nov 20 '19 at 17:36

0 Answers0