vue-test-utils

How to test vue router beforeRouteUpdate navigation guard?

一笑奈何 提交于 2021-02-10 14:32:23
问题 First off, I'm using Vue-property-decorator. My component has a component route, defined like this. @Component({ components: { ComponentA, ComponentB }, beforeRouteUpdate (to, _from, next) { const { checkInDate, checkOutDate, items, currency, locale } = to.query; const queryFullfilled = !!checkInDate && !!checkOutDate && !!items.length && !!currency && !!locale; if ([BOOKING_PAGE, RESERVATION_PAGE].indexOf(to.name) > -1 && queryFullfilled) { this.validateRooms(); } next(); } }) export default

How to test vue router beforeRouteUpdate navigation guard?

旧时模样 提交于 2021-02-10 14:32:07
问题 First off, I'm using Vue-property-decorator. My component has a component route, defined like this. @Component({ components: { ComponentA, ComponentB }, beforeRouteUpdate (to, _from, next) { const { checkInDate, checkOutDate, items, currency, locale } = to.query; const queryFullfilled = !!checkInDate && !!checkOutDate && !!items.length && !!currency && !!locale; if ([BOOKING_PAGE, RESERVATION_PAGE].indexOf(to.name) > -1 && queryFullfilled) { this.validateRooms(); } next(); } }) export default

Simulate select with element-ui and vue-test-utils

放肆的年华 提交于 2021-01-27 04:00:19
问题 I'm doing unit tests with Jest and Element-ui in Vue on a component which contains a select with 2 options. I am selecting an option from a dropdown and then checking that an action has been called. 1) With normal select and option HTML tags this works perfectly. // Fruit.vue <template lang="pug"> select( v-model="fruit" ) option( v-for="item in fruits" :label="item.label" :value="item.value" ) </template> <script> export default { data () { return { fruits: [ { label: 'Banana', value: false

vue.js vuetify test-utils warning : Vue warn]: Invalid prop: type check failed for prop “src”. Expected String, got Object

为君一笑 提交于 2020-12-15 05:19:07
问题 Using v-parallax vuetify with a prop to display an asset URL (it's a recommended hack..) <v-parallax :src="parallaxUrl()"> methods: { parallaxUrl() { return require("@/assets/images/hero.jpeg"); }, I get the image displayed correctly, BUT running test:unit , I aslo get a warning , as the v-parallax require a string and not an object... The test pass correctly ( it's only a warning..) , however is there a way to get rid of this warning ? thanks for feedback 回答1: When you require an file, it

Test on function call in Vue template only passes if the function is called with parentheses

这一生的挚爱 提交于 2020-12-12 11:28:32
问题 I am using Vue v2.6 with Jest (v24.9) and Vue-Test-Utils (v1.03). In order to mock a method I have seen two different syntaxes, wrapper.vm.updateCart = jest.fn(); and wrapper.setMethods({ updateCart: jest.fn() }); but the first is not documented, while the second is deprecated (see docs). The problem is that with both these methods, the only way to make a test pass is to call the method with the parentheses inside the template, which is weird because all the docs I've read somehow encourage

How do you open a bootstrap-vue modal with vue-test-utils?

丶灬走出姿态 提交于 2020-12-08 16:53:16
问题 I'm using bootstrap as my design framework and have been using bootstrap-vue. Now I would like to implement some tests to go along with my components. I'm writing a very simple test to make sure a modal is opened. What do I use in vue-test-utils to open the bootstrap-vue modal? I'm using the basics that come with Laravel, bootstrap-vue, vue-test-utils, mocha, and mocha-webpack. I'm trying to open the modal with wrapper.find('#modal-1').trigger('click') . I've tried using a directive <b-button

Mocking methods on a Vue instance during TDD

你说的曾经没有我的故事 提交于 2020-11-24 16:15:25
问题 I'm learning TDD whilst building my Vue app, and trying to abide by the strict laws of only writing enough production code to satisfy a failing unit test. I am really enjoying this approach, but I have run into a roadblock in regards to adding methods to a Vue instance, and testing that they have been called when the event fires from the element in the template. I cannot find any suggestions as to how I can mock a Vue method given that if I mock the proxied method, it ends up not being called

Mocking methods on a Vue instance during TDD

混江龙づ霸主 提交于 2020-11-24 16:11:51
问题 I'm learning TDD whilst building my Vue app, and trying to abide by the strict laws of only writing enough production code to satisfy a failing unit test. I am really enjoying this approach, but I have run into a roadblock in regards to adding methods to a Vue instance, and testing that they have been called when the event fires from the element in the template. I cannot find any suggestions as to how I can mock a Vue method given that if I mock the proxied method, it ends up not being called

Mocking methods on a Vue instance during TDD

北慕城南 提交于 2020-11-24 16:11:49
问题 I'm learning TDD whilst building my Vue app, and trying to abide by the strict laws of only writing enough production code to satisfy a failing unit test. I am really enjoying this approach, but I have run into a roadblock in regards to adding methods to a Vue instance, and testing that they have been called when the event fires from the element in the template. I cannot find any suggestions as to how I can mock a Vue method given that if I mock the proxied method, it ends up not being called

Mocking methods on a Vue instance during TDD

末鹿安然 提交于 2020-11-24 16:10:35
问题 I'm learning TDD whilst building my Vue app, and trying to abide by the strict laws of only writing enough production code to satisfy a failing unit test. I am really enjoying this approach, but I have run into a roadblock in regards to adding methods to a Vue instance, and testing that they have been called when the event fires from the element in the template. I cannot find any suggestions as to how I can mock a Vue method given that if I mock the proxied method, it ends up not being called