diff --git a/js/src/util.js b/js/src/util.js index d130682e351d..95186bb6626a 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 e7e22cea97cb..18a05b269f3f 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 = $('
').appendTo($('#qunit-fixture'))