Skip to content

Commit

Permalink
[js] fix capabilities serialize
Browse files Browse the repository at this point in the history
Closes #1950

Signed-off-by: Jason Leyba <jmleyba@gmail.com>
  • Loading branch information
cnishina authored and jleyba committed Apr 12, 2016
1 parent 5166a60 commit 6435986
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
2 changes: 2 additions & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Deprecated `Promise#thenFinally()` - use `Promise#finally()`. The thenFinally
shim added to the promise module in v2.53.0 will be removed in v3.0
Sorry for the churn!
* FIXED: capabilities serialization now properly handles undefined vs.
false-like values.

## v2.53.1

Expand Down
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/lib/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ function serialize(caps) {
let ret = {};
for (let key of caps.keys()) {
let cap = caps.get(key);
if (cap) {
if (cap !== undefined && cap !== null) {
ret[key] = cap;
}
}
Expand Down
35 changes: 31 additions & 4 deletions javascript/node/selenium-webdriver/test/lib/capabilities_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,36 @@ describe('Capabilities', function() {
assert.equal('def', caps.get('abc'));
});

it('can be serialized', function() {
let m = new Map([['one', 123], ['abc', 'def']]);
let caps = new Capabilities(m);
assert.deepEqual({one: 123, abc: 'def'}, caps[Symbols.serialize]());
describe('serialize', function() {
it('works for simple capabilities', function() {
let m = new Map([['one', 123], ['abc', 'def']]);
let caps = new Capabilities(m);
assert.deepEqual({one: 123, abc: 'def'}, caps[Symbols.serialize]());
});

it('does not omit capabilities set to a false-like value', function() {
let caps = new Capabilities;
caps.set('bool', false);
caps.set('number', 0);
caps.set('string', '');

assert.deepEqual(
{bool: false, number: 0, string: ''},
caps[Symbols.serialize]());
});

it('omits capabilities with a null value', function() {
let caps = new Capabilities;
caps.set('foo', null);
caps.set('bar', 123);
assert.deepEqual({bar: 123}, caps[Symbols.serialize]());
});

it('omits capabilities with an undefined value', function() {
let caps = new Capabilities;
caps.set('foo', undefined);
caps.set('bar', 123);
assert.deepEqual({bar: 123}, caps[Symbols.serialize]());
});
});
});

0 comments on commit 6435986

Please sign in to comment.