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.

[Bug Report] Unable to mock $vuetify in unit tests

See original GitHub issue

Environment

Vuetify Version: 2.2.11 Vue Version: 2.6.11 Browsers: Safari 13.1 OS: Mac OS 10.14.6

Steps to reproduce

  1. yarn
  2. yarn test:unit
  3. open file example.spec.js and see snapshot result.

Expected Behavior

I want to mock instance variable $vuetify.breakpoint.smAndDown by providing a mock like described in the docu https://vuetifyjs.com/en/getting-started/unit-testing/ and https://vue-test-utils.vuejs.org/api/options.html#mocks. I installed Vuetify like described in a config file setup.jest.js and configured jest to use it.

I expected that in my test that mocked smAndDown is set to true.

Actual Behavior

$vuetify instance variable is not mockable. The actual implementation is not overwritten by passing a mock object either to new Vuetify() nor to shallowMount or mount.

Reproduction Link

https://github.com/Bastczuak/vuetify-mock-issue

Other comments

Please fix the issue creator! I was not able to create an issue in Chrome browser because after submitting a new issue I got redirected to my account email settings.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

17reactions
Bastczuakcommented, Sep 30, 2020

This is for my people who are coming from google. After reading code and trying around, I now have a working solution for mocking vuetify services in unit tests. But be careful, I have no idea if it works with typescript! Here are some examples.

    const breakpoint = {
      init: jest.fn(),
      framework: {},
      smAndDown: true,
    }
    const vuetify = new Vuetify()
    vuetify.framework.breakpoint = breakpoint
    const wrapper = shallowMount(Component, {
      vuetify,
    })
    const goTo = jest.fn()
    goTo.init = jest.fn()
    goTo.framework = {}
    const vuetify = new Vuetify()
    vuetify.framework.goTo = goTo

    const wrapper = shallowMount(Component, {
      vuetify,
    })

Your welcome @ ElVisPL @benjamindedonder.

@johnleider can we add this to the official documentation?

7reactions
ElVisPLcommented, Jun 1, 2020

https://github.com/vuetifyjs/vuetify/issues/11388 Still doesn’t work when mocking breakpoint

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit testing — Vuetify
When testing these components, you will need to provide vue-test-utils with a mock object. // test/CustomAlert.spec.js // Libraries import ...
Read more >
Vue.js and Vuetify unit testing with Jest - IOBIO
Unit testing is a software testing method where the individual units/ components of a software are tested to verify that each unit works...
Read more >
How can I solve error when unit testing with mocha on vue?
I had install it. So I run npm run test:unit , there exist error like this : npm ERR! Failed at the test-vuetify@0.1.0...
Read more >
Testing Vue Components With Cypress - CSS-Tricks
Most of our unit and component tests are written with Jest and Vue ... an “end-to-end” test that mocks API responses and doesn't...
Read more >
[Solved]-Jest testing Vuetify v-img-Vue.js - appsloveworld.com
Unable to perform click on Vuetify vSwitch when testing with Jest · How to solve 'SyntaxError: Unexpected identifier' while testing vuetify components 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