mirror of
https://github.com/appium/appium.git
synced 2026-10-28 12:21:20 +08:00
* Some problems with parsing `{protocol: <protocol>, value: <value>}`
* `(!_.isNil(driverRes.value)` was incorrect check because `value` can be undefined or null; replaced it with `_.has(driverRes, 'value')` to check that the `value` property was set
* ```
if (driverRes.value) {
driverRes = driverRes.value;
}
```
was also incorrect because `driverRes.value` may be false-y
* Moved logic into it's own function and then added tests to cover the problem cases
38 lines
1.8 KiB
JavaScript
38 lines
1.8 KiB
JavaScript
// transpile:mocha
|
|
|
|
import '../..'; // NOTE: For some reason this file needs to be imported to prevent a babel error
|
|
import chai from 'chai';
|
|
import chaiAsPromised from 'chai-as-promised';
|
|
import { parseProtocol } from '../../lib/protocol/protocol';
|
|
|
|
chai.should();
|
|
chai.use(chaiAsPromised);
|
|
|
|
describe('Protocol', async function () {
|
|
|
|
describe('#parseProtocol', function () {
|
|
it('should parse {protocol: "MJSONWP"} as MJSONWP', function () {
|
|
parseProtocol({protocol: 'MJSONWP', value: undefined}).should.eql({isW3C: false, isMJSONWP: true, value: undefined});
|
|
});
|
|
it('should parse {protocol: "W3C"} as W3C', function () {
|
|
parseProtocol({protocol: 'W3C', value: undefined}).should.eql({isW3C: true, isMJSONWP: false, value: undefined});
|
|
});
|
|
it('should parse {protocol: "MJSONWP", value: false} as MJSONWP with value: false', function () {
|
|
parseProtocol({protocol: 'MJSONWP', value: false}).should.eql({isW3C: false, isMJSONWP: true, value: false});
|
|
});
|
|
it('should parse {protocol: "W3C", value: 0} as W3C with value: 0', function () {
|
|
parseProtocol({protocol: 'W3C', value: 0}).should.eql({isW3C: true, isMJSONWP: false, value: 0});
|
|
});
|
|
it('should parse {protocol: "MJSONWP", value: "string"}', function () {
|
|
parseProtocol({protocol: 'MJSONWP', value: "string"}).should.eql({isW3C: false, isMJSONWP: true, value: "string"});
|
|
});
|
|
it('should parse {protocol: "W3C", value: {obj}}', function () {
|
|
const value = {hello: 'world', goodbye: 'whirl'};
|
|
parseProtocol({protocol: 'MJSONWP', value}).should.eql({isW3C: false, isMJSONWP: true, value});
|
|
});
|
|
it('should throw if {protocol: "MJSONWP", error}', function () {
|
|
(() => parseProtocol({protocol: 'W3C', error: new Error('some error')})).should.throw(/some error/);
|
|
});
|
|
});
|
|
});
|