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.

Tests using createLocalVue() display warning (rc.20)

See original GitHub issue

Describe the bug

Tests using bootstrap-vue and createLocalVue() output the following warning

[BootstrapVue warn]: Multiple instances of Vue detected!
See: https://bootstrap-vue.js.org/docs#using-module-bundlers

The test code looks like:

  beforeEach(() => {
    const localVue = createLocalVue();
    localVue.use(BootstrapVue);

    wrapper = mount(SomeComponent, { localVue });
  });

Expected behavior

Tests run successfully without warnings.

Versions

Libraries:

  • bootstrap-vue: 2.0.0-rc.20
  • bootstrap: 4.3.1
  • vue: 2.6.10
  • jest: 24.8.0
  • vue-jest: 3.0.4
  • @vue/test-utils: 1.0.0-beta.29

Environment:

Jest

Possible solution?!

The issue can be fixed by moving the localVue.use() statement from the test file

  beforeEach(() => {
    const localVue = createLocalVue();
    sectionPallet = mount(SectionPallet, { localVue });
  });

to the jestSetup.js.

import Vue from 'vue';
//...
Vue.use(BootstrapVue);

Now the tests run successfully. But the question is: Is that intended?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
tmorehousecommented, May 27, 2019

Version 2.0.0-rc.21 has been released

1reaction
tmorehousecommented, May 15, 2019

The warnings should not cause tests to fail (but will place console warns in your test logs)

Adding the Vue.use in jestSetup.js would include the full library in each test, rather than testing for just the certain components in our test suites.

You can disable BootstrapVue warns by setting process.env.BOOTSTRAP_VUE_NO_WARN = true before running your tests.

https://bootstrap-vue.js.org/docs/misc/settings#disabling-bootstrapvue-console-warnings

You can also set up a console.warn mock to trap the warns (which we have done in some of our tests):

  beforeAll(() => {
    // Prevent multiple Vue warnings in tests
    jest.spyOn(console, 'warn').mockImplementation(() => {})
    // Install plugin after we have trapped console.warn
    localVue.use(toastPlugin)
  })

  afterAll(() => {
    console.warn.mockClear()
  })
Read more comments on GitHub >

github_iconTop Results From Across the Web

createLocalVue() - Vue Test Utils
createLocalVue returns a Vue class for you to add components, mixins and install plugins without polluting the global Vue class. The errorHandler option...
Read more >
Chapter 10. Testing Vue Router
This chapter covers. Writing unit tests for components that use Vue Router properties; Writing unit tests for the RouterLink component; Using Vue ...
Read more >
typeerror: cannot read properties of undefined ... - You.com
I'm new to unit tests and currently I'm using Jest with Vue2 Test Utils to create tests in a project already under development....
Read more >
'Route with name 'something' does not exist' vue-router ...
I've created a Codepen (includes the whole file) of a page I was testing. It shows my basic setup and some ways I...
Read more >
Vue.js and Vuetify unit testing with Jest - IOBIO
(The temperature is displayed in an alert component. ) Check the output. //tests/unit/DisplayTemperature.spec.js import { createLocalVue ...
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