Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed May 11, 2024
1 parent bf2ae0d commit 32728cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/commands/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {AndroidDriver} from 'appium-android-driver';
* @returns {import('@appium/types').StringRecord<string>}
*/
export function mobileCommandsMapping() {
const commonMapping = AndroidDriver.prototype.mobileCommandsMapping.call(this);
const commonMapping = new AndroidDriver().mobileCommandsMapping.call(this);
return {
...commonMapping,
dragGesture: 'mobileDragGesture',
Expand Down Expand Up @@ -59,7 +59,7 @@ export function mobileCommandsMapping() {
* @returns {Promise<any>}
*/
export async function executeMobile(mobileCommand, opts = {}) {
return await AndroidDriver.prototype.executeMobile.call(this, mobileCommand, preprocessOptions(opts));
return await new AndroidDriver().executeMobile.call(this, mobileCommand, preprocessOptions(opts));
}

// #region Internal Helpers
Expand Down
13 changes: 6 additions & 7 deletions test/unit/commands/general-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const {expect} = chai;
chai.use(chaiAsPromised).use(sinonChai);

describe('General', function () {
/** @type {AndroidUiautomator2Driver} */
let driver;
/** @type {import('sinon').SinonSandbox} */
let sandbox;
Expand Down Expand Up @@ -39,8 +38,8 @@ describe('General', function () {
});

it('should raise error on non-existent mobile command', async function () {
await expect(driver.executeMobile('mobile: fruta', {})).to.be.rejectedWith(
/Unknown mobile command "mobile: fruta"/
await expect(driver.execute('mobile: fruta', {})).to.be.rejectedWith(
/Unknown mobile command "fruta"/
);
});

Expand All @@ -50,7 +49,7 @@ describe('General', function () {
// implementation, which is stubbed out.
it('should call sensorSet', async function () {
sandbox.stub(driver, 'sensorSet');
await driver.executeMobile('mobile: sensorSet', {
await driver.execute('mobile: sensorSet', {
sensorType: 'acceleration',
value: '0:9.77631:0.812349',
});
Expand All @@ -74,18 +73,18 @@ describe('General', function () {
});

it('should call mobileInstallMultipleApks', async function () {
await driver.executeMobile('mobile: installMultipleApks', {apks: ['/path/to/test/apk.apk']});
await driver.execute('mobile: installMultipleApks', {apks: ['/path/to/test/apk.apk']});
expect(adb.installMultipleApks).to.have.been.calledOnceWith(['/path/to/test/apk.apk']);
});

it('should reject if no apks were given', async function () {
await expect(
driver.executeMobile('mobile: installMultipleApks', {apks: []})
driver.execute('mobile: installMultipleApks', {apks: []})
).to.be.rejectedWith('No apks are given to install');
});

it('should reject if no apks were given', async function () {
await expect(driver.executeMobile('mobile: installMultipleApks')).to.be.rejectedWith(
await expect(driver.execute('mobile: installMultipleApks')).to.be.rejectedWith(
'No apks are given to install'
);
});
Expand Down

0 comments on commit 32728cb

Please sign in to comment.