Skip to content

Commit 6435986

Browse files
cnishinajleyba
authored andcommitted
[js] fix capabilities serialize
Closes #1950 Signed-off-by: Jason Leyba <[email protected]>
1 parent 5166a60 commit 6435986

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Deprecated `Promise#thenFinally()` - use `Promise#finally()`. The thenFinally
66
shim added to the promise module in v2.53.0 will be removed in v3.0
77
Sorry for the churn!
8+
* FIXED: capabilities serialization now properly handles undefined vs.
9+
false-like values.
810

911
## v2.53.1
1012

javascript/node/selenium-webdriver/lib/capabilities.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ function serialize(caps) {
431431
let ret = {};
432432
for (let key of caps.keys()) {
433433
let cap = caps.get(key);
434-
if (cap) {
434+
if (cap !== undefined && cap !== null) {
435435
ret[key] = cap;
436436
}
437437
}

javascript/node/selenium-webdriver/test/lib/capabilities_test.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,36 @@ describe('Capabilities', function() {
7676
assert.equal('def', caps.get('abc'));
7777
});
7878

79-
it('can be serialized', function() {
80-
let m = new Map([['one', 123], ['abc', 'def']]);
81-
let caps = new Capabilities(m);
82-
assert.deepEqual({one: 123, abc: 'def'}, caps[Symbols.serialize]());
79+
describe('serialize', function() {
80+
it('works for simple capabilities', function() {
81+
let m = new Map([['one', 123], ['abc', 'def']]);
82+
let caps = new Capabilities(m);
83+
assert.deepEqual({one: 123, abc: 'def'}, caps[Symbols.serialize]());
84+
});
85+
86+
it('does not omit capabilities set to a false-like value', function() {
87+
let caps = new Capabilities;
88+
caps.set('bool', false);
89+
caps.set('number', 0);
90+
caps.set('string', '');
91+
92+
assert.deepEqual(
93+
{bool: false, number: 0, string: ''},
94+
caps[Symbols.serialize]());
95+
});
96+
97+
it('omits capabilities with a null value', function() {
98+
let caps = new Capabilities;
99+
caps.set('foo', null);
100+
caps.set('bar', 123);
101+
assert.deepEqual({bar: 123}, caps[Symbols.serialize]());
102+
});
103+
104+
it('omits capabilities with an undefined value', function() {
105+
let caps = new Capabilities;
106+
caps.set('foo', undefined);
107+
caps.set('bar', 123);
108+
assert.deepEqual({bar: 123}, caps[Symbols.serialize]());
109+
});
83110
});
84111
});

0 commit comments

Comments
 (0)