From 5142de7e592abc0a791ea3465616795c91219bcc Mon Sep 17 00:00:00 2001 From: Johann-S Date: Fri, 31 Mar 2017 10:03:54 +0200 Subject: [PATCH] Popover + Tooltip - fix error when content or title is a number --- js/src/tooltip.js | 8 ++++++++ js/tests/unit/popover.js | 18 ++++++++++++++++++ js/tests/unit/tooltip.js | 16 ++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 5fd4987b90..1ff2c4f6e0 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -605,6 +605,14 @@ const Tooltip = (($) => { } } + if (config.title && typeof config.title === 'number') { + config.title = config.title.toString() + } + + if (config.content && typeof config.content === 'number') { + config.content = config.content.toString() + } + Util.typeCheckConfig( NAME, config, diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index 64c8c556ac..eaa9fa0c0d 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -364,4 +364,22 @@ $(function () { }) .modal('show') }) + + QUnit.test('should convert number to string without error for content and title', function (assert) { + assert.expect(2) + var done = assert.async() + var $popover = $('@mdo') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + title: 5, + content: 7 + }) + .on('shown.bs.popover', function () { + assert.strictEqual($('.popover .popover-title').text(), '5') + assert.strictEqual($('.popover .popover-content').text(), '7') + done() + }) + + $popover.bootstrapPopover('show') + }) }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index e739f06a50..8cb1a6fdf1 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -886,4 +886,20 @@ $(function () { $el.bootstrapTooltip('hide') }) + + QUnit.test('should convert number in title to string', function (assert) { + assert.expect(1) + var done = assert.async() + var $el = $('') + .appendTo('#qunit-fixture') + .bootstrapTooltip('show') + .on('shown.bs.tooltip', function () { + var tooltip = $el.data('bs.tooltip') + var $tooltip = $(tooltip.getTipElement()) + assert.strictEqual($tooltip.children().text(), '7') + done() + }) + + $el.bootstrapTooltip('show') + }) })