Files
appium/test/protocol/protocol-specs.js
T
Dan Graham a74d25cb1e Fix: Throw error after parsing protocol from proxied response (#211)
* Before it was throwing immediately which meant we weren't parsing the protocol and weren't showing the proper error responses
* If proxied W3C error doesn't have an error, make it `Unknown Error`
2018-05-14 08:36:49 -07:00

39 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 () {
const error = new Error('some error');
parseProtocol({protocol: 'W3C', error}).error.should.equal(error);
});
});
});