Skip to content

Commit c5f2fa9

Browse files
committed
fix: ensure totype always return stringified null when null passed
1 parent 51268b7 commit c5f2fa9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

js/src/util/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ const MILLISECONDS_MULTIPLIER = 1000
1010
const TRANSITION_END = 'transitionend'
1111

1212
// Shoutout AngusCroll (https://goo.gl/pxwQGp)
13-
const toType = obj => ({}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase())
13+
const toType = obj => {
14+
if (obj === null) {
15+
return `${obj}`
16+
}
17+
18+
return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()
19+
}
1420

1521
/**
1622
* --------------------------------------------------------------------------

js/tests/unit/util/index.spec.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ describe('Util', () => {
198198
})
199199

200200
describe('typeCheckConfig', () => {
201+
const namePlugin = 'collapse'
202+
201203
it('should check type of the config object', () => {
202-
const namePlugin = 'collapse'
203204
const defaultType = {
204205
toggle: 'boolean',
205206
parent: '(string|element)'
@@ -213,6 +214,20 @@ describe('Util', () => {
213214
Util.typeCheckConfig(namePlugin, config, defaultType)
214215
}).toThrow(new Error('COLLAPSE: Option "parent" provided type "number" but expected type "(string|element)".'))
215216
})
217+
218+
it('should return null to string when null passed', () => {
219+
const defaultType = {
220+
toggle: 'boolean',
221+
parent: '(null|element)'
222+
}
223+
const config = {
224+
toggle: true,
225+
parent: null
226+
}
227+
228+
Util.typeCheckConfig(namePlugin, config, defaultType)
229+
expect().nothing()
230+
})
216231
})
217232

218233
describe('makeArray', () => {

0 commit comments

Comments
 (0)