How to make mock/make it optional?
See original GitHub issueI integrated Vee-Validate
in my Form-Group component, but if the consumer doesn’t use VV, I need a graceful degrade.
Figured I can do this:
inject: {
$validator: {
from: '$validator',
default() {
return {}
}
}
}
Edit 2: Scrap that, it has to be more empiric:
created() {
if (this.$root.$validator) {
this.$validator = this.$root.$validator
} else {
this.$validator = {}
}
}
But I still have to deal with the missing directive exception.
Edit 3: Ended up with this:
// Resources
import VeeValidate from 'vee-validate'
// Implementation
export default {
directives: {
validate: {
...VeeValidate.directive
}
},
data() {
return {
$validator: {}
}
},
created() {
if (this.$root.$validator) {
this.$validator = this.$root.$validator
} else {
this.$validator = new VeeValidate.Validator()
}
},
computed: {
errors() {
return this.$validator.errors
}
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to make a mock return 'false' for 'Optional.isPresent()'?
If you just want an Optional returning false for isPresent() , you don't need to mock the Optional at all but just create...
Read more >Make it easier to to mock java.lang.Optional as return value of ...
When you do extensive testing/mocking on some APIs which return Optionals on you end up writing somehting like Mockito.when(foo.getBaa()).
Read more >How to mock repository findById thenReturn() Optional?
Try to mock a repository findById method, but no idea use thenReturn() to return an object, as it accepts an Optional ?
Read more >A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
To create a spy, you need to call Mockito's static method spy() and pass it an instance to spy on. Calling methods of...
Read more >Create hydrated mock | TS auto mock
Do you need to mock optional properties or union types that may be undefined? Say hello to createHydratedMock, it will help you create...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes you can, vee-validate supports custom component validation and
v-model
directive if used on the same element node. here is a basic implementation:// Input.vue
Now you can use it like this:
Good point. In my case, I’m developing an internal components library, so I actually want to have my validation implementation centralized and under control.