Skip to content
Advertisement

error in unit test vue.js karma (webpack): undefined is not a constructor

I’m using the webpack template generated by Vue’s CLI and have been trying to add some unit tests. And example has already been provided and it works perfectly:

JavaScript

Then I try to add another test which I copied straight from Vue’s documentation (Documentation link) but something weird happened:

JavaScript

I got the following error:

JavaScript

So it seems like Hello.created gives me an undefined, but as you can see, I also console.log it to double check, and it does give it the desired result: undefined

Can anyone give me some help on what happened and how to fix it? I’ve already tried the solution here and still couldn’t make it work.

For your reference, here’s how Hello.vue looks like:

JavaScript

Advertisement

Answer

Turns out the template is actually using chai instead of jasmine to do unit test.

In this case,

expect(typeof Hello.created).to.equal('function')

or

expect(Hello.created).to.be.a('function')

both work.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement