mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-09 07:06:36 +02:00
fix: ensure totype
always returns stringified null/undefined when null/undefined is passed (#30383)
This commit is contained in:
@@ -10,7 +10,13 @@ const MILLISECONDS_MULTIPLIER = 1000
|
|||||||
const TRANSITION_END = 'transitionend'
|
const TRANSITION_END = 'transitionend'
|
||||||
|
|
||||||
// Shoutout AngusCroll (https://goo.gl/pxwQGp)
|
// Shoutout AngusCroll (https://goo.gl/pxwQGp)
|
||||||
const toType = obj => ({}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase())
|
const toType = obj => {
|
||||||
|
if (obj === null || obj === undefined) {
|
||||||
|
return `${obj}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
|
@@ -198,8 +198,9 @@ describe('Util', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('typeCheckConfig', () => {
|
describe('typeCheckConfig', () => {
|
||||||
|
const namePlugin = 'collapse'
|
||||||
|
|
||||||
it('should check type of the config object', () => {
|
it('should check type of the config object', () => {
|
||||||
const namePlugin = 'collapse'
|
|
||||||
const defaultType = {
|
const defaultType = {
|
||||||
toggle: 'boolean',
|
toggle: 'boolean',
|
||||||
parent: '(string|element)'
|
parent: '(string|element)'
|
||||||
@@ -213,6 +214,34 @@ describe('Util', () => {
|
|||||||
Util.typeCheckConfig(namePlugin, config, defaultType)
|
Util.typeCheckConfig(namePlugin, config, defaultType)
|
||||||
}).toThrow(new Error('COLLAPSE: Option "parent" provided type "number" but expected type "(string|element)".'))
|
}).toThrow(new Error('COLLAPSE: Option "parent" provided type "number" but expected type "(string|element)".'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should return null stringified when null is passed', () => {
|
||||||
|
const defaultType = {
|
||||||
|
toggle: 'boolean',
|
||||||
|
parent: '(null|element)'
|
||||||
|
}
|
||||||
|
const config = {
|
||||||
|
toggle: true,
|
||||||
|
parent: null
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.typeCheckConfig(namePlugin, config, defaultType)
|
||||||
|
expect().nothing()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return undefined stringified when undefined is passed', () => {
|
||||||
|
const defaultType = {
|
||||||
|
toggle: 'boolean',
|
||||||
|
parent: '(undefined|element)'
|
||||||
|
}
|
||||||
|
const config = {
|
||||||
|
toggle: true,
|
||||||
|
parent: undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.typeCheckConfig(namePlugin, config, defaultType)
|
||||||
|
expect().nothing()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('makeArray', () => {
|
describe('makeArray', () => {
|
||||||
|
Reference in New Issue
Block a user