How to use the opn.mock function in opn

To help you get started, we’ve selected a few opn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github evilz / vscode-reveal / test / browserHelper.jest.ts View on Github external
test('Should use headless chrome only when needed', async () => {
    (fs.statSync as any).mockImplementation((_) => true);
    (os.platform as any).mockImplementation(() => 'win32');
    (opn as any).mockImplementation(async (url, opts) => { })
    await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl")

    expect(opn.mock.calls.length).toBe(1);
    expect(opn.mock.calls[0][0]).toBe("http://theurl")
    expect(opn.mock.calls[0][1]).toStrictEqual({ app: DEFAULT_CHROME_PATH.WINx86 })

    await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl", true)

    expect(opn.mock.calls.length).toBe(2);
    expect(opn.mock.calls[1][0]).toBe("http://theurl")
    expect(opn.mock.calls[1][1]).toStrictEqual({ app: [DEFAULT_CHROME_PATH.WINx86, "--headless"] })
})
github evilz / vscode-reveal / test / browserHelper.jest.ts View on Github external
test('Should use headless chrome only when needed', async () => {
    (fs.statSync as any).mockImplementation((_) => true);
    (os.platform as any).mockImplementation(() => 'win32');
    (opn as any).mockImplementation(async (url, opts) => { })
    await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl")

    expect(opn.mock.calls.length).toBe(1);
    expect(opn.mock.calls[0][0]).toBe("http://theurl")
    expect(opn.mock.calls[0][1]).toStrictEqual({ app: DEFAULT_CHROME_PATH.WINx86 })

    await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl", true)

    expect(opn.mock.calls.length).toBe(2);
    expect(opn.mock.calls[1][0]).toBe("http://theurl")
    expect(opn.mock.calls[1][1]).toStrictEqual({ app: [DEFAULT_CHROME_PATH.WINx86, "--headless"] })
})

opn

Open stuff like URLs, files, executables. Cross-platform.

MIT
Latest version published 5 years ago

Package Health Score

63 / 100
Full package analysis

Popular opn functions