Can't stub $router in unit tests
See original GitHub issueSo I’m writing a test that does something like:
t.stub($store);
const $router = { push: t.spy() };
const data = { email: 'test@wb.test', password: 'password' };
const wrapper = mount(Login, { data, globals: { $router, $store } });
t.stub($store, 'getters').value({ isLoggedIn: true });
And while the $store
stub is available on this
in the component the $router
one is not set. I’m assuming there is some special behaviour with the $router
global?
This is a unit test so I’m not installing vue-router
or vuex
in the tests, I’m stubbing them out using Sinon instead.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
How can I unit test a component that uses the Router in ...
In Angular 2.0.0, I am unit testing a component that uses Router. However I get the 'Supplied parameters do not match any signature...
Read more >Stub $route in Vue unit tests - Dev tips and tricks
Learn how to stub the $route in Vue unit tests. This tutorial walks through 4 ways of stubbing the vue-router $route object.
Read more >To stub or not to stub the router service in integration tests
To tests this, I would write an integration test where I would stub the router service and provide it with a dummy currentRouteName...
Read more >Using Stubs and Mocks in Jasmine to test your Angular code
Unit tests allow us to automatically test our code under a variety of conditions to prove that it works and when it breaks...
Read more >Testing Vue Router
You can use a mocked router to avoid caring about the implementation details of Vue Router in your unit tests. Instead of using...
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’m currently unable to coax avoriaz to accept my mock router or router-link stubs, and so the tests insist that the router-link element is unknown. I’ve tried
shallow
, stubbing a router-link component manually and stubbing the globals all to no avail. If there’s a guide that can walk me through this I’d be happy to give it a read.I’ll write a guide for this at some point