From aff115219ee47b261b943bbe65cf5919fe021a22 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Wed, 18 Mar 2020 12:10:55 +0100 Subject: fix: ensure `totype` always returns stringified null/undefined when null/undefined is passed (#30383) --- js/tests/unit/util/index.spec.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'js/tests') diff --git a/js/tests/unit/util/index.spec.js b/js/tests/unit/util/index.spec.js index 42c273f06..57ca1a9c7 100644 --- a/js/tests/unit/util/index.spec.js +++ b/js/tests/unit/util/index.spec.js @@ -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)' @@ -213,6 +214,34 @@ 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 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', () => { -- cgit v1.2.3