{"size": 783, "ext": "js", "max_stars_repo_path": "detox/src/devices/__mocks__/Device.js", "max_stars_repo_name": "arendruni/Detox", "max_stars_repo_stars_event_min_datetime": "2018-09-03T05:13:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T13:50:16.000Z", "max_issues_repo_path": "detox/src/devices/__mocks__/Device.js", "max_issues_repo_name": "arendruni/Detox", "max_issues_repo_issues_event_min_datetime": "2018-09-02T09:31:02.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:16:05.000Z", "max_forks_repo_path": "detox/src/devices/__mocks__/Device.js", "max_forks_repo_name": "arendruni/Detox", "max_forks_repo_forks_event_min_datetime": "2018-09-04T10:50:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T14:14:45.000Z"}
{"max_stars_count": 6289, "max_issues_count": 1942, "max_forks_count": 1672, "avg_line_length": 29.0, "max_line_length": 75, "alphanum_fraction": 0.6756066411}
const Deferred = require('../../utils/Deferred');
const Device = jest.requireActual('../Device');
const FakeDevice = jest.genMockFromModule('../Device');

FakeDevice.useRealConstructor = () => {
  FakeDevice.mockImplementationOnce((...args) => {
    const device = new FakeDevice();
    Object.assign(device, new Device(...args));
    return device;
  });
};

FakeDevice.setInfiniteMethod = (methodName) => {
  FakeDevice.mockImplementationOnce(() => {
    const device = new FakeDevice();
    device.deferred = new Deferred();
    device[methodName].mockReturnValue(device.deferred.promise);
    device._cleanup.mockImplementation(() => {
      device.deferred.reject(`Fake error: aborted device.${methodName}()`);
    });

    return device;
  });
};

module.exports = FakeDevice;
