Unit testing: 'Injection "$validator" not found'
See original GitHub issueVersions:
- VueJs: 2.5.13
- Vee-Validate: 2.0.4
Description:
I have installed vee-validate
with the inject property on false, and then I have a child component that has an inject: ['$validator']
and a parent with $_veeValidate.validator = 'new'
.
This works perfectly everywhere besides during unit testing.
Steps To Reproduce:
this is my component test and the BaseInput component it is just a component that handles the error handling and the input itself, then it passes all the validation to the parent.
import { mount, createLocalVue } from '@vue/test-utils'
import idObj from 'identity-obj-proxy';
import BaseInput from '@/components/BaseInput'
import VeeValidate from 'vee-validate'
const localVue = createLocalVue()
localVue.use(VeeValidate, {
inject: false
})
describe('<base-input>', () => {
it ('should render one input tag', () => {
const wrapper = mount(BaseInput, {
localVue,
propsData: {
name: 'foo'
},
mocks: {
$style: idObj
}
})
expect(wrapper.contains('input')).toBe(true)
})
})
When I run the test, it passes but I have a warning in the terminal
[Vue warn]: Injection "$validator" not found
Do you know how to avoid this behavior?
Thanks for you time
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Dependency inside a Validator class not initialize in unit test
My question is if the Validator is init as such in unit test, how can I provide the inject of accountService during unit...
Read more >Test Extensions — FluentValidation documentation
FluentValidation provides some extensions that can aid with testing your validator classes. We recommend treating validators as 'black boxes' - provide ...
Read more >Testing Dependency Injection • Angular - codecraft.tv
When the component is created since it has its own injector it will resolve the AuthService itself and not forward the request to...
Read more >How to mock dependencies when unit testing custom ...
Since we are interested in unit testing, there's no Spring application context available, hence we must manually instantiate a Validator and ...
Read more >Basics of testing components - Angular
The component truly is the template and the class working together. ... testing the component class alone, without DOM involvement, can validate much...
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
I guess that’s because there is no provider for the $validator dependency in the component tree, It works fine in production because there is a root instance that will always have its own validator and can provide it. In tests, it could be different.
Anyways you can fix that in your tests by making the root instance provide the validator instance:
@logaretm I have small problem with that, but it may be also related with vue-test-utils (on beta.12 this issue didn’t occur).
In unit tests I have computed variable:
After blur on input ->
wrapper.find('input').trigger('blur')
-> I expect message to be shown, but in my case it’s not.Here are reproduction links:
In first case it works (just click in input, and then click outside - you’ll see error message below). Second situation is a bit different, I set inject to false:
and inject inside component:
and then it didn’t works. Do you have idea what may be the issue here ?