Skip to content

Commit

Permalink
Mock timezone so date tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
imurchie committed Jun 25, 2018
1 parent 20c9e4a commit 67ec56e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-mocha": "^4.7.0",
"eslint-plugin-promise": "^3.3.1",
"gulp": "^3.9.1",
"mocha": "^5.1.1",
"mock-fs": "^4.5.0",
"gulp": "^3.9.1",
"moment-timezone": "^0.5.21",
"pre-commit": "^1.1.3",
"sinon": "^6.0.0",
"unzip": "^0.1.11",
Expand Down
11 changes: 9 additions & 2 deletions test/unit/commands/general-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { fs } from 'appium-support';
import Bootstrap from 'appium-android-bootstrap';
import B from 'bluebird';
import ADB from 'appium-adb';
import moment from 'moment-timezone';


chai.should();
Expand Down Expand Up @@ -49,6 +50,12 @@ describe('General', function () {
});
});
describe('getDeviceTime', function () {
beforeEach(function () {
moment.tz.setDefault('Atlantic/Reykjavik');
});
afterEach(function () {
moment.tz.setDefault();
});
it('should return device time', async function () {
sandbox.stub(driver.adb, 'shell');
driver.adb.shell.returns(' 2018-06-09T16:21:54+0900 ');
Expand All @@ -61,11 +68,11 @@ describe('General', function () {
await driver.getDeviceTime('YYYY-MM-DD').should.become('2018-06-09');
driver.adb.shell.calledWithExactly(['date', '+%Y-%m-%dT%T%z']).should.be.true;
});
it('should thorws error if shell command failed', async function () {
it('should throw error if shell command failed', async function () {
sandbox.stub(driver.adb, 'shell').throws();
await driver.getDeviceTime().should.be.rejected;
});
it('should thorws error if format is not string', async function () {
it('should throw error if format is not string', async function () {
sandbox.stub(driver.adb, 'shell').throws();
await driver.getDeviceTime({}).should.be.rejectedWith(
/The format specifier is expected to be a valid string specifier/
Expand Down

0 comments on commit 67ec56e

Please sign in to comment.