{"size": 1650, "ext": "js", "max_stars_repo_path": "packages/webdriverio/tests/commands/browser/mock.test.js", "max_stars_repo_name": "RedMickey/webdriverio", "max_stars_repo_stars_event_min_datetime": "2021-07-15T21:54:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-15T21:54:52.000Z", "max_issues_repo_path": "packages/webdriverio/tests/commands/browser/mock.test.js", "max_issues_repo_name": "RedMickey/webdriverio", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/webdriverio/tests/commands/browser/mock.test.js", "max_forks_repo_name": "RedMickey/webdriverio", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.5, "max_line_length": 94, "alphanum_fraction": 0.5709090909}
import { remote } from '../../../src'

const clientMock = {
    send: jest.fn(),
    on: jest.fn()
}
const pageMock = {
    target: jest.fn().mockReturnValue({
        createCDPSession: jest.fn().mockReturnValue(Promise.resolve(clientMock))
    })
}
const puppeteerMock = {
    pages: jest.fn().mockReturnValue([pageMock])
}

jest.mock('../../../src/utils/interception/webdriver', () => class WebDriverInterceptionMock {
    constructor () {
        this.init = jest.fn()
    }
})

describe('custom$', () => {
    let browser

    it('should enable the fetch domain if not already done', async () => {
        browser = await remote({
            baseUrl: 'http://foobar.com',
            capabilities: {
                browserName: 'devtools'
            }
        })

        browser.puppeteer = puppeteerMock

        expect(clientMock.send).toBeCalledTimes(0)
        await browser.mock('/foobar')
        expect(clientMock.send).toBeCalledWith('Fetch.enable', expect.any(Object))
        expect(clientMock.on).toBeCalledWith('Fetch.requestPaused', expect.any(Function))

        await browser.mock('/foobar')
        expect(clientMock.send).toBeCalledTimes(1)
    })

    it('should mock using WebDriver capabilities', async () => {
        browser = await remote({
            baseUrl: 'http://foobar.com',
            capabilities: {
                browserName: 'chrome',
                'sauce:options': {
                    extendedDebugging: true
                }
            }
        })

        browser.puppeteer = puppeteerMock
        const mock = await browser.mock('/foobar')
        expect(mock.init).toBeCalledWith()
    })
})
