Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defaultValue check for null #5551

Merged
merged 6 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Change Log
* Added a Sandcastle demo for setting time with the Clock API [#5457](https://github.com/AnalyticalGraphicsInc/cesium/pull/5457);
* Added support for `ParticleSystem`s. [#5212](https://github.com/AnalyticalGraphicsInc/cesium/pull/5212)
* Added `Cesium.Math.randomBetween`.
* `defaultValue` updated to check for Null.

### 1.34 - 2017-06-01

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/defaultValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions Specs/Core/defaultValueSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*global defineSuite*/
defineSuite([
'Core/defaultValue'
], function(
defaultValue) {
'use strict';

it('Works with first parameter undefined', function() {
expect(function(){
defaultValue.defaultValue(undefined, 5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just become expect(defaultValue(undefined,5).toEqual(5), I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omh1280 yup, updated with the changes.

}).toEqual(5);
});

it('Works with first parameter null', function() {
expect(function(){
defaultValue.defaultValue(null, 5);
}).toEqual(5);
});

it('Works with first parameter not undefined and not null', function() {
expect(function(){
defaultValue.defaultValue(1, 5);
}).toEqual(1);
});

});