Skip to content

Commit 4b5d916

Browse files
authored
fix: don't display warning messages when in production (closes #5598) (#5763)
* fix: don't display BootstrapVue warning messages when in production * Update bv-tooltip.js * Update README.md * Update bv-tooltip.js * Update bv-tooltip.js * Update pagination.js * Update tooltip.spec.js
1 parent c691472 commit 4b5d916

File tree

5 files changed

+86
-16
lines changed

5 files changed

+86
-16
lines changed

docs/markdown/reference/settings/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,13 @@ the config object to the Nuxt.js plugin module.
168168

169169
## Disabling BootstrapVue console warnings
170170

171-
BootstrapVue will warn (via `console.warn`) when you try and use a deprecated prop, or pass an
171+
BootstrapVue will warn (via `console.warn()`) when you try and use a deprecated prop, or pass an
172172
invalid value to certain props. These warnings are provided to help you ensure that your application
173173
is using the correct props and values.
174174

175-
In some cases, you may want to disable these warnings (not recommended). You can do so by setting
176-
the following process environment variable:
175+
BootstrapVue automatically disables warnings in production mode (`NODE_ENV=production`). If you want
176+
to disable the warnings in other scenarios (not recommended), you can do so by setting the following
177+
process environment variable:
177178

178179
<!-- eslint-disable no-unused-vars -->
179180

src/components/pagination/pagination.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ export const BPagination = /*#__PURE__*/ Vue.extend({
119119
return
120120
}
121121

122-
console.log(evt, pageNumber)
123-
124122
// Update the `v-model`
125123
this.currentPage = pageNumber
126124
// Emit event triggered by user interaction

src/components/tooltip/helpers/bv-tooltip.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,12 @@ export const BVTooltip = /*#__PURE__*/ Vue.extend({
248248
this.listen()
249249
} else {
250250
/* istanbul ignore next */
251-
warn('Unable to find target element in document.', this.templateType)
251+
warn(
252+
isString(this.target)
253+
? `Unable to find target element by ID "#${this.target}" in document.`
254+
: 'The provided target is no valid HTML element.',
255+
this.templateType
256+
)
252257
}
253258
})
254259
},
@@ -513,13 +518,14 @@ export const BVTooltip = /*#__PURE__*/ Vue.extend({
513518
},
514519
// --- Utility methods ---
515520
getTarget() {
516-
// Handle case where target may be a component ref
517-
let target = this.target ? this.target.$el || this.target : null
518-
// If an ID
519-
target = isString(target) ? getById(target.replace(/^#/, '')) : target
520-
// If a function
521-
target = isFunction(target) ? target() : target
522-
// If an element ref
521+
let { target } = this
522+
if (isString(target)) {
523+
target = getById(target.replace(/^#/, ''))
524+
} else if (isFunction(target)) {
525+
target = target()
526+
} else if (target) {
527+
target = target.$el || target
528+
}
523529
return isElement(target) ? target : null
524530
},
525531
getPlacementTarget() {

src/components/tooltip/tooltip.spec.js

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const MODAL_CLOSE_EVENT = 'bv::modal::hidden'
77
// Our test application
88
const App = {
99
props: [
10+
'target',
1011
'triggers',
1112
'show',
1213
'noninteractive',
@@ -22,7 +23,7 @@ const App = {
2223
],
2324
render(h) {
2425
const tipProps = {
25-
target: 'foo',
26+
target: this.target || 'foo',
2627
triggers: this.triggers,
2728
show: this.show,
2829
noninteractive: this.noninteractive || false,
@@ -47,7 +48,8 @@ const App = {
4748
type: 'button',
4849
disabled: this.btnDisabled || null,
4950
title: this.titleAttr || null
50-
}
51+
},
52+
ref: 'target'
5153
},
5254
'text'
5355
),
@@ -283,6 +285,68 @@ describe('b-tooltip', () => {
283285
wrapper.destroy()
284286
})
285287

288+
it('providing the trigger element by function works', async () => {
289+
jest.useFakeTimers()
290+
const container = createContainer()
291+
const wrapper = mount(App, {
292+
attachTo: container,
293+
propsData: {
294+
target: () => wrapper.vm.$refs.target,
295+
triggers: 'click',
296+
show: false
297+
},
298+
slots: {
299+
default: 'title'
300+
}
301+
})
302+
303+
expect(wrapper.vm).toBeDefined()
304+
await waitNT(wrapper.vm)
305+
await waitRAF()
306+
await waitNT(wrapper.vm)
307+
await waitRAF()
308+
jest.runOnlyPendingTimers()
309+
310+
expect(wrapper.element.tagName).toBe('ARTICLE')
311+
expect(wrapper.attributes('id')).toBeDefined()
312+
expect(wrapper.attributes('id')).toEqual('wrapper')
313+
314+
// The trigger button
315+
const $button = wrapper.find('button')
316+
expect($button.exists()).toBe(true)
317+
expect($button.attributes('id')).toBeDefined()
318+
expect($button.attributes('id')).toEqual('foo')
319+
expect($button.attributes('aria-describedby')).not.toBeDefined()
320+
321+
// <b-tooltip> wrapper
322+
const $tipHolder = wrapper.findComponent(BTooltip)
323+
expect($tipHolder.exists()).toBe(true)
324+
325+
// Activate tooltip by trigger
326+
await $button.trigger('click')
327+
await waitRAF()
328+
await waitRAF()
329+
jest.runOnlyPendingTimers()
330+
await waitNT(wrapper.vm)
331+
await waitRAF()
332+
333+
expect($button.attributes('id')).toBeDefined()
334+
expect($button.attributes('id')).toEqual('foo')
335+
expect($button.attributes('aria-describedby')).toBeDefined()
336+
// ID of the tooltip that will be in the body
337+
const adb = $button.attributes('aria-describedby')
338+
339+
// Find the tooltip element in the document
340+
const tip = document.getElementById(adb)
341+
expect(tip).not.toBe(null)
342+
expect(tip).toBeInstanceOf(HTMLElement)
343+
expect(tip.tagName).toEqual('DIV')
344+
expect(tip.classList.contains('tooltip')).toBe(true)
345+
expect(tip.classList.contains('b-tooltip')).toBe(true)
346+
347+
wrapper.destroy()
348+
})
349+
286350
it('activating trigger element (click) opens tooltip', async () => {
287351
jest.useFakeTimers()
288352
const wrapper = mount(App, {

src/utils/env.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ export const getEnv = (key, fallback = null) => {
7272
return env[key] || fallback
7373
}
7474

75-
export const getNoWarn = () => getEnv('BOOTSTRAP_VUE_NO_WARN')
75+
export const getNoWarn = () =>
76+
getEnv('BOOTSTRAP_VUE_NO_WARN') || getEnv('NODE_ENV') === 'production'

0 commit comments

Comments
 (0)