Skip to content

Commit

Permalink
Backport (#30383)
Browse files Browse the repository at this point in the history
fix: ensure totype always return stringified null when null passed
  • Loading branch information
Johann-S authored and XhmikosR committed Mar 23, 2020
1 parent 6b0b4a6 commit a9efc1c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions js/src/util.js
Expand Up @@ -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()
}

Expand Down
20 changes: 20 additions & 0 deletions js/tests/unit/util.js
Expand Up @@ -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'))
Expand Down

0 comments on commit a9efc1c

Please sign in to comment.