Код: Выделить всё
MyComponent.vue
Код: Выделить всё
const connectService = async () => {
loading.value = true;
const payload = {
type: 'messaging',
credentials: {
username: user.value,
password: pass.value,
...(phone.value && { phoneNumber: phone.value })
}
};
try {
await store.connect(payload);
if (store.connectionStatus === 'connected') {
if (requiresVerification.value) {
step.value = 'VerifyAccount';
} else {
step.value = 'SuccessScreen';
}
}
} catch (error) {
console.error(error);
} finally {
loading.value = false;
}
};
< /code>
test.spec.ts
Код: Выделить всё
wrapper.vm.phone = '+1234567890';
// Mock store response before calling function
store.$patch({
connectionStatus: 'connected'
});
wrapper.vm.requiresVerification = false;
// Call the function
await wrapper.vm.connectService();
// Let Vue resolve everything
await wrapper.vm.$nextTick();
// Expect the `step` to update
expect(wrapper.vm.step).toBe('SuccessScreen');
< /code>
The test fails. The step is still the initial value and doesn't update to 'SuccessScreen'. What I noticed is that wrapper.vm.phone
Подробности моей среды-
"vue": "3.5.13",
"@vue/test-utils": "2.4.6",
"vite": "6.2.5",
< /code>
Can anyone please help me understand what I'm doing wrong?
Подробнее здесь: https://stackoverflow.com/questions/796 ... ge-in-test