During testing my new VueJS project with Jest I encountered problem caused by props validation.
All of my tests that has proper mocked data, pass the validator from ponent.
I would like to test situation when I mock wrong data
and pass it to the ponent. I know that when the validator
from ponent return false
, vuemon.js
console.error this:
console.error node_modules/vue/dist/vuemon.js:576
[Vue warn]: Invalid prop: custom validator check failed for prop "SOMETHING".
I would like to catch this error in my Jest test, but none of methods below I've tried work for me:
Using
spyOn(console, 'error')
and thenexcept(spy.calls.mostRecent()).toHaveBeenCalled()
.Registering
console.*
in globals like thisglobal.console {...}
I have no idea what should I try now or what I am doing wrong.
Thanks for the answers, cheers.
During testing my new VueJS project with Jest I encountered problem caused by props validation.
All of my tests that has proper mocked data, pass the validator from ponent.
I would like to test situation when I mock wrong data
and pass it to the ponent. I know that when the validator
from ponent return false
, vue.mon.js
console.error this:
console.error node_modules/vue/dist/vue.mon.js:576
[Vue warn]: Invalid prop: custom validator check failed for prop "SOMETHING".
I would like to catch this error in my Jest test, but none of methods below I've tried work for me:
Using
spyOn(console, 'error')
and thenexcept(spy.calls.mostRecent()).toHaveBeenCalled()
.Registering
console.*
in globals like thisglobal.console {...}
I have no idea what should I try now or what I am doing wrong.
Thanks for the answers, cheers.
Share Improve this question asked Nov 24, 2017 at 14:03 Wojtek JureczkaWojtek Jureczka 1612 silver badges8 bronze badges2 Answers
Reset to default 5Solved:
I had to use my wrapper.vm object, something like this:
expect(wrapper.vm.$options.props.YOUR_PROPS_OBJECT.validator(YOUR_WRONG_PROPS)).toBe(false);
One more way to deal with validator
testing:
the ponent can be used directly, for instance, if the the ponent, being tested is named App
and the property name is p
then
expect(App.props.p.validator(arg)).toBe(res)
is the test for it.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745093083a4610810.html
评论列表(0条)