aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohann-S <[email protected]>2020-03-20 22:33:23 +0100
committerXhmikosR <[email protected]>2020-03-31 21:11:29 +0300
commitdabd458b4b817136e2a34c97d40e8854c344bf69 (patch)
tree675d460ce2690f127325d21905bbe749d82e62f2
parent0c8d8a48e143206452a3cb3ee2d8cf1e49488dbb (diff)
downloadbootstrap-dabd458b4b817136e2a34c97d40e8854c344bf69.tar.xz
bootstrap-dabd458b4b817136e2a34c97d40e8854c344bf69.zip
Backport (#30383)
fix: ensure totype always return stringified null when null passed
-rw-r--r--js/src/util.js4
-rw-r--r--js/tests/unit/util.js20
2 files changed, 24 insertions, 0 deletions
diff --git a/js/src/util.js b/js/src/util.js
index d130682e3..95186bb66 100644
--- a/js/src/util.js
+++ b/js/src/util.js
@@ -19,6 +19,10 @@ const MILLISECONDS_MULTIPLIER = 1000
// Shoutout AngusCroll (https://goo.gl/pxwQGp)
function toType(obj) {
+ if (obj === null || typeof obj === 'undefined') {
+ return `${obj}`
+ }
+
return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()
}
diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js
index e7e22cea9..18a05b269 100644
--- a/js/tests/unit/util.js
+++ b/js/tests/unit/util.js
@@ -51,6 +51,26 @@ $(function () {
}
})
+ QUnit.test('Util.typeCheckConfig should return null/undefined stringified when passed', function (assert) {
+ assert.expect(1)
+ var namePlugin = 'collapse'
+ var defaultType = {
+ toggle: '(null|undefined)'
+ }
+ var config = {
+ toggle: null
+ }
+
+ Util.typeCheckConfig(namePlugin, config, defaultType)
+
+ // eslint-disable-next-line
+ config.toggle = undefined
+
+ Util.typeCheckConfig(namePlugin, config, defaultType)
+
+ assert.strictEqual(true, true)
+ })
+
QUnit.test('Util.isElement should check if we passed an element or not', function (assert) {
assert.expect(3)
var $div = $('<div id="test"></div>').appendTo($('#qunit-fixture'))