Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export platform specific objects through proxy #374

Merged
merged 19 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion detox/src/Detox.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Detox {
async init(userParams) {
const sessionConfig = await this._getSessionConfig();
const defaultParams = {launchApp: true, initGlobals: true};
const params = Object.assign(userParams, defaultParams);
const params = Object.assign(defaultParams, userParams || {});

if (!this.userSession) {
this.server = new DetoxServer(new URL(sessionConfig.server).port);
Expand Down
58 changes: 43 additions & 15 deletions detox/src/exportWrapper.test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
const iosExports = require('./ios/expect');
const androidExports = require('./android/expect');
const exportWrapper = require('./exportWrapper');
const platform = require('./platform');
jest.mock('./ios/expect');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure you reset the mocks, instead of doing it statically, require and mock everything in beforeEach inside the suite (in the describe)

jest.mock('./android/expect');
const iosExports = require('./ios/expect');
const androidExports = require('./android/expect');

describe('exportWrapper', () => {
const mockDevice = {};
const mockDevice = {method: jest.fn()};

it(`proxies ios specific objects`, async () => {
const arg1 = 1;
const arg2 = 'test';

it(`exports ios specific objects`, async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are not being passed locally with wallaby, I think its related to the fact that they are not being reset correctly

platform.set('ios.none', mockDevice);
iosExports.by.method = jest.fn();

exportWrapper.device.method(arg1, arg2);
expect(mockDevice.method).toHaveBeenCalledWith(arg1, arg2);

exportWrapper.expect(arg1, arg2);
expect(iosExports.expect).toHaveBeenCalledWith(arg1, arg2);

expect(exportWrapper.device).toBe(mockDevice);
expect(exportWrapper.expect).toBe(iosExports.expect);
expect(exportWrapper.element).toBe(iosExports.element);
expect(exportWrapper.waitFor).toBe(iosExports.waitFor);
expect(exportWrapper.by).toBe(iosExports.by);
exportWrapper.element(arg1, arg2);
expect(iosExports.element).toHaveBeenCalledWith(arg1, arg2);

exportWrapper.waitFor(arg1, arg2);
expect(iosExports.waitFor).toHaveBeenCalledWith(arg1, arg2);

exportWrapper.by.method(arg1, arg2);
expect(iosExports.by.method).toHaveBeenCalledWith(arg1, arg2);
});

it(`exports android specific objects`, async () => {
it(`proxies android specific objects`, async () => {
const arg1 = 1;
const arg2 = 'test';

platform.set('android.attached', mockDevice);
androidExports.by.method = jest.fn();

exportWrapper.device.method(arg1, arg2);
expect(mockDevice.method).toHaveBeenCalledWith(arg1, arg2);

exportWrapper.expect(arg1, arg2);
expect(androidExports.expect).toHaveBeenCalledWith(arg1, arg2);

exportWrapper.element(arg1, arg2);
expect(androidExports.element).toHaveBeenCalledWith(arg1, arg2);

exportWrapper.waitFor(arg1, arg2);
expect(androidExports.waitFor).toHaveBeenCalledWith(arg1, arg2);

expect(exportWrapper.device).toBe(mockDevice);
expect(exportWrapper.expect).toBe(androidExports.expect);
expect(exportWrapper.element).toBe(androidExports.element);
expect(exportWrapper.waitFor).toBe(androidExports.waitFor);
expect(exportWrapper.by).toBe(androidExports.by);
exportWrapper.by.method(arg1, arg2);
expect(androidExports.by.method).toHaveBeenCalledWith(arg1, arg2);
});
});