i want to know how to set composition API in mount second option plz #346
Answered
by
cexbrayat
byeongwan-kim
asked this question in
Q&A
-
hello, i attach sample code. // Password.vue
<template>
<input
v-model="password"
>
</template>
<script>
import { ref } from 'vue';
export default {
name: 'Password',
setup() {
const password = ref('long');
return {
password,
};
},
};
</script> // Password.spec.js
import { ref } from 'vue';
import { mount } from '@vue/test-utils';
import Password from 'main/components/Password';
test('Change password value', () => {
const wrapper = mount(Password, {
setup() {
const password = ref('short');
return {
password,
};
},
});
console.log(wrapper.vm.password); // expect: short
// result: long
}); |
Beta Was this translation helpful? Give feedback.
Answered by
cexbrayat
Feb 3, 2021
Replies: 1 comment 2 replies
-
Hi @EXEM-KBW You can simply do something like: test('Change password value', async () => {
const wrapper = mount(Password);
// change the password value
wrapper.vm.password = 'short';
// refresh the DOM
await nextTick();
const input = wrapper.get('input');
expect(input.element.value).toBe('short');
}); |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
byeongwan-kim
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @EXEM-KBW
You can simply do something like: