question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't stub $router in unit tests

See original GitHub issue

So 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:closed
  • Created 6 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
LoneRiflecommented, Oct 20, 2017

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.

1reaction
eddyerburghcommented, Jul 15, 2017

I’ll write a guide for this at some point

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found