Mock $refs
See original GitHub issueIt would be useful to be able to mock $refs.
Currently, as far as I understand there is no way to test a method that calls a childs methods via $refs.
methodToTest ( ) {
this.a = 1
this.$refs.childComponent.childsMethod()
}
---
undefined is not an object (evaluating 'this.$refs.childComponent.childsMethod')
Issue Analytics
- State:
- Created 6 years ago
- Reactions:21
- Comments:34 (9 by maintainers)
Top Results From Across the Web
Vue jest $refs function and component mocking issue
I'm trying to mock the library and write the test but i'm getting a this.$refs.headroom._setHeightOffset is not a function it seems like the ......
Read more >How to stub named ref in vue test
Hi I need help to mock/stub something like this.$refs.nameNotComponent.focus() How I can achieve this? nameNotComponent is a name I choosed ...
Read more >Mock Ref return values and ref locals | Telerik JustMock - Telerik
JustMock's powerful capabilities enable you to mock methods with ref return references in order to test your code in perfect isolation.
Read more >chromium / external / github.com / golang / mock - Google Git
GoMock is a mocking framework for the Go programming language. It integrates well with Go's built-in testing package, but can be used in...
Read more >How to mock a same flow-ref (or) sub-flow with different ...
I have a mule flow in which there are two flow-refs referring to same sub-flow. I have to mock those two flow-refs with...
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
Hi @ddykhoff, thanks for the fiddle.
The reason you can’t call the method on the ref is because shallow stubs all the child components. The $refs object is still populated, but the toast component doesn’t have any methods (because it’s been stubbed).
You can use
mountinstead ofshallowif you want to interact with a child components methods. Alternatively, you could useshallowand pass a custom stub:For me helped the way of changing
shallowMounttomount, and mocking the ref method like this:Hope this may be useful for someone.