diff --git a/CHANGES.md b/CHANGES.md index 7acf03608649..4d0b19db3c05 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -30,6 +30,7 @@ Change Log * Fixed a bug where camera zooming worked incorrectly when the display height was greater than the display width [#5421](https://github.com/AnalyticalGraphicsInc/cesium/pull/5421) * Updated glTF/glb MIME types. [#5420](https://github.com/AnalyticalGraphicsInc/cesium/issues/5420) * Added `Cesium.Math.randomBetween`. +* Modified `defaultValue` to check for both `undefined` and `null`. [#5551](https://github.com/AnalyticalGraphicsInc/cesium/pull/5551) ### 1.34 - 2017-06-01 diff --git a/Source/Core/defaultValue.js b/Source/Core/defaultValue.js index 1389059d0970..011640f1d06c 100644 --- a/Source/Core/defaultValue.js +++ b/Source/Core/defaultValue.js @@ -19,7 +19,7 @@ define([ * param = Cesium.defaultValue(param, 'default'); */ function defaultValue(a, b) { - if (a !== undefined) { + if (a !== undefined && a !== null) { return a; } return b; diff --git a/Specs/Core/defaultValueSpec.js b/Specs/Core/defaultValueSpec.js new file mode 100644 index 000000000000..19f6b98096d3 --- /dev/null +++ b/Specs/Core/defaultValueSpec.js @@ -0,0 +1,20 @@ +/*global defineSuite*/ +defineSuite([ + 'Core/defaultValue' + ], function( + defaultValue) { + 'use strict'; + + it('Works with first parameter undefined', function() { + expect(defaultValue(undefined, 5)).toEqual(5); + }); + + it('Works with first parameter null', function() { + expect(defaultValue(null, 5)).toEqual(5); + }); + + it('Works with first parameter not undefined and not null', function() { + expect(defaultValue(1, 5)).toEqual(1); + }); + +});