forked from facebookarchive/WebDriverAgent
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for setValue/setValueImmediate (#507)
* Add unit tests for setValue/setValueImmediate * Add error for weird values * Change error message for bad arguments to setValue
- Loading branch information
Showing
5 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,6 @@ before_install: | |
# code from http://stackoverflow.com/a/24600210/375688 | ||
- sed -i '' 's/[email protected]:/https:\/\/github.com\//' /Users/travis/build/appium/appium-xcuitest-driver/.gitmodules | ||
- git submodule update --init --recursive | ||
before_script: | ||
- node --version | ||
- npm install | ||
script: | ||
- npm run lint && npm run mocha -- -t 480000 --recursive build/test/$TEST -g @skip-ci -i | ||
- if [ -n "$COVERALLS" ]; then npm run coverage; fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import sinon from 'sinon'; | ||
import XCUITestDriver from '../../..'; | ||
import chai from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import { withMocks } from 'appium-test-support'; | ||
|
||
|
||
chai.should(); | ||
chai.use(chaiAsPromised); | ||
|
||
describe('element commands', function () { | ||
let driver = new XCUITestDriver(); | ||
let proxySpy = sinon.stub(driver, 'proxyCommand'); | ||
|
||
afterEach(function () { | ||
proxySpy.reset(); | ||
}); | ||
|
||
describe('setValueImmediate', withMocks({driver}, (mocks) => { | ||
it('should call setValue', async function () { | ||
mocks.driver | ||
.expects('setValue') | ||
.once().withExactArgs('hello', 2).returns(); | ||
await driver.setValueImmediate('hello', 2); | ||
mocks.driver.verify(); | ||
}); | ||
})); | ||
|
||
describe('setValue', function () { | ||
const elementId = 2; | ||
const expectedEndpoint = `/element/${elementId}/value`; | ||
const expectedMethod = 'POST'; | ||
|
||
describe('success', function () { | ||
afterEach(function () { | ||
proxySpy.calledOnce.should.be.true; | ||
proxySpy.firstCall.args[0].should.eql(expectedEndpoint); | ||
proxySpy.firstCall.args[1].should.eql(expectedMethod); | ||
}); | ||
|
||
it('should proxy string as array of characters', async function () { | ||
await driver.setValue('hello', elementId); | ||
proxySpy.firstCall.args[2].should.eql({value: ['h', 'e', 'l', 'l', 'o']}); | ||
}); | ||
it('should proxy integer as array of characters', async function () { | ||
await driver.setValue(1234, elementId); | ||
proxySpy.firstCall.args[2].should.eql({value: ['1', '2', '3', '4']}); | ||
}); | ||
it('should proxy string array as array of characters', async function () { | ||
await driver.setValue(['hel', 'lo'], elementId); | ||
proxySpy.firstCall.args[2].should.eql({value: ['h', 'e', 'l', 'l', 'o']}); | ||
}); | ||
it('should proxy integer array as array of characters', async function () { | ||
await driver.setValue([1234], elementId); | ||
proxySpy.firstCall.args[2].should.eql({value: ['1', '2', '3', '4']}); | ||
}); | ||
}); | ||
|
||
describe('failure', function () { | ||
it('should throw invalid argument exception for null', async function () { | ||
await driver.setValue(null, elementId) | ||
.should.eventually.be.rejectedWith(/Only strings and arrays of strings are supported as input arguments. Received: 'null'/); | ||
}); | ||
it('should throw invalid argument exception for object', async function () { | ||
await driver.setValue({hi: 'there'}, elementId) | ||
.should.eventually.be.rejectedWith(/Only strings and arrays of strings are supported as input arguments. Received: '{"hi":"there"}'/); | ||
}); | ||
}); | ||
}); | ||
}); |