Skip to content

Commit 0caa29b

Browse files
authored
feat: don't warn about multiple Vue instances when testing in JSDOM (closes bootstrap-vue#3303) (bootstrap-vue#3315)
1 parent 231acdf commit 0caa29b

File tree

6 files changed

+8
-24
lines changed

6 files changed

+8
-24
lines changed

src/components/modal/helpers/bv-modal.spec.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,9 @@ describe('$bvModal', () => {
66
const localVue = new CreateLocalVue()
77

88
beforeAll(() => {
9-
// Prevent multiple Vue warnings in tests
10-
jest.spyOn(console, 'warn').mockImplementation(() => {})
11-
// Install plugin after we have trapped console.warn
129
localVue.use(modalPlugin)
1310
})
1411

15-
afterAll(() => {
16-
console.warn.mockClear()
17-
})
18-
1912
it('$bvModal.show() and $bvModal.hide() works', async () => {
2013
const App = localVue.extend({
2114
render(h) {

src/components/toast/helpers/bv-toast.spec.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,9 @@ describe('$bvToast', () => {
66
const localVue = new CreateLocalVue()
77

88
beforeAll(() => {
9-
// Prevent multiple Vue warnings in tests
10-
jest.spyOn(console, 'warn').mockImplementation(() => {})
11-
// Install plugin after we have trapped console.warn
129
localVue.use(toastPlugin)
1310
})
1411

15-
afterAll(() => {
16-
console.warn.mockClear()
17-
})
18-
1912
it('$bvToast.show() and $bvToast.hide() works', async () => {
2013
const App = localVue.extend({
2114
render(h) {

src/utils/config.spec.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ import AlertPlugin from '../../src/components/alert'
1616
import BVConfigPlugin from '../../src/bv-config'
1717

1818
describe('utils/config', () => {
19-
beforeEach(() => {
20-
// Prevent multiple Vue warnings in tests
21-
jest.spyOn(console, 'warn').mockImplementation(() => {})
22-
})
23-
2419
afterEach(() => {
25-
console.warn.mockClear()
2620
resetConfig()
2721
})
2822

src/utils/dom.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ export const MutationObs =
5555
// Normalize event options based on support of passive option
5656
// Exported only for testing purposes
5757
export const parseEventOptions = options => {
58-
if (!hasPassiveEventSupport) {
58+
/* istanbul ignore else: can't test in JSDOM, as it supports passive */
59+
if (hasPassiveEventSupport) {
60+
return isObject(options) ? options : { useCapture: Boolean(options || false) }
61+
} else {
5962
// Need to translate to actual Boolean value
6063
return Boolean(isObject(options) ? options.useCapture : options)
6164
}
62-
return isObject(options) ? options : { useCapture: Boolean(options || false) }
6365
}
6466

6567
// Attach an event listener to an element

src/utils/env.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const hasMutationObserverSupport =
1515

1616
export const isBrowser = hasWindowSupport && hasDocumentSupport && hasNavigatorSupport
1717

18+
export const isJSDOM = isBrowser && navigator.userAgent.includes('jsdom')
19+
1820
// Determine if the browser supports the option passive for events
1921
export const hasPassiveEventSupport = (() => {
2022
let passiveEventSupported = false

src/utils/plugins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import OurVue from './vue'
22
import warn from './warn'
33
import { setConfig } from './config'
4-
import { hasWindowSupport } from './env'
4+
import { hasWindowSupport, isJSDOM } from './env'
55

66
const MULTIPLE_VUE_WARNING = `Multiple instances of Vue detected!
77
See: https://bootstrap-vue.js.org/docs#using-module-bundlers`
@@ -14,7 +14,7 @@ let checkMultipleVueWarned = false
1414
*/
1515
export const checkMultipleVue = Vue => {
1616
/* istanbul ignore next */
17-
if (!checkMultipleVueWarned && OurVue !== Vue) {
17+
if (!checkMultipleVueWarned && OurVue !== Vue && !isJSDOM) {
1818
warn(MULTIPLE_VUE_WARNING)
1919
checkMultipleVueWarned = true
2020
}

0 commit comments

Comments
 (0)