Skip to content

Commit

Permalink
fix: ensure totype always return stringified null when null passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Mar 11, 2020
1 parent 51268b7 commit c5f2fa9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion js/src/util/index.js
Expand Up @@ -10,7 +10,13 @@ const MILLISECONDS_MULTIPLIER = 1000
const TRANSITION_END = 'transitionend'

// 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) {
return `${obj}`
}

return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()
}

/**
* --------------------------------------------------------------------------
Expand Down
17 changes: 16 additions & 1 deletion js/tests/unit/util/index.spec.js
Expand Up @@ -198,8 +198,9 @@ describe('Util', () => {
})

describe('typeCheckConfig', () => {
const namePlugin = 'collapse'

it('should check type of the config object', () => {
const namePlugin = 'collapse'
const defaultType = {
toggle: 'boolean',
parent: '(string|element)'
Expand All @@ -213,6 +214,20 @@ describe('Util', () => {
Util.typeCheckConfig(namePlugin, config, defaultType)
}).toThrow(new Error('COLLAPSE: Option "parent" provided type "number" but expected type "(string|element)".'))
})

it('should return null to string when null passed', () => {
const defaultType = {
toggle: 'boolean',
parent: '(null|element)'
}
const config = {
toggle: true,
parent: null
}

Util.typeCheckConfig(namePlugin, config, defaultType)
expect().nothing()
})
})

describe('makeArray', () => {
Expand Down

0 comments on commit c5f2fa9

Please sign in to comment.