Skip to content

Commit 57ecb15

Browse files
committed
fix(orientation) : do not throw if "executionContext" is not inited yet
1 parent 978a81c commit 57ecb15

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

lib/command-helpers/test-context.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
'use strict';
22

33
const getTestContext = (context) => {
4-
return context.type === 'hook' && /^"before each"/.test(context.title)
4+
return context && context.type === 'hook' && /^"before each"/.test(context.title)
55
? context.ctx.currentTest
66
: context;
77
};
88

99
const resetTestContextValues = (context, keys = []) => {
1010
const testCtx = getTestContext(context);
1111

12+
if (!testCtx) {
13+
return;
14+
}
15+
1216
[].concat(keys).forEach((key) => {
1317
delete testCtx[key];
1418
});

lib/commands/orientation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = (browser) => {
66
const baseOrientationFn = browser.orientation;
77

88
browser.addCommand('orientation', async (orientation) => {
9-
if (orientation) {
9+
if (orientation && browser.executionContext) {
1010
resetTestContextValues(browser.executionContext, [TOP_TOOLBAR_SIZE, BOTTOM_TOOLBAR_LOCATION, WEB_VIEW_SIZE]);
1111
}
1212

test/lib/command-helpers/test-context.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,33 @@ describe('"test-context" helper', () => {
2727
assert.equal(ctx, browser.executionContext.ctx.currentTest);
2828
});
2929

30-
it('should return test context for not hook', () => {
31-
browser.executionContext = {some: 'test'};
32-
33-
const ctx = testCtx.getTestContext(browser.executionContext);
34-
35-
assert.equal(ctx, browser.executionContext);
30+
[
31+
{
32+
name: 'not hook',
33+
executionContext: {some: 'test'}
34+
},
35+
{
36+
name: 'falsy value',
37+
executionContext: undefined
38+
}
39+
].forEach(({name, executionContext}) => {
40+
it(`shoult return passed context for ${name}`, () => {
41+
browser.executionContext = executionContext;
42+
43+
const ctx = testCtx.getTestContext(browser.executionContext);
44+
45+
assert.equal(ctx, browser.executionContext);
46+
});
3647
});
3748
});
3849

3950
describe('"resetTestContextValues" method', () => {
51+
it('should not throw if test context is falsy', () => {
52+
browser.executionContext = undefined;
53+
54+
assert.doesNotThrow(() => testCtx.resetTestContextValues(browser.executionContext, ['foo', 'bar']));
55+
});
56+
4057
it('should reset value in test context for one passed key', () => {
4158
browser.executionContext = {foo: 'value'};
4259

test/lib/commands/orientation.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,22 @@ describe('"orientation" command', () => {
4646
);
4747
});
4848

49-
it('should not reset toolbar and web view values in test context if "orientation" is not passed', async () => {
50-
addOrientationCommand(browser);
49+
describe('should not reset toolbar and web view values in test context if', () => {
50+
it('"orientation" is not passed', async () => {
51+
addOrientationCommand(browser);
52+
53+
await browser.orientation();
54+
55+
assert.notCalled(resetTestContextValues);
56+
});
57+
58+
it('"browser.executionContext" is not inited yet', async () => {
59+
browser.executionContext = undefined;
60+
addOrientationCommand(browser);
5161

52-
await browser.orientation();
62+
await browser.orientation('landscape');
5363

54-
assert.notCalled(resetTestContextValues);
64+
assert.notCalled(resetTestContextValues);
65+
});
5566
});
5667
});

0 commit comments

Comments
 (0)