UNPKG

playwright-fluent

Version:
66 lines (65 loc) 2.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("path")); const playwright_1 = require("playwright"); const SUT = tslib_1.__importStar(require("../index")); const dom_actions_1 = require("../../../dom-actions"); const hover_on_handle_1 = require("../hover-on-handle"); describe('scroll to handle', () => { let browser = undefined; // eslint-disable-next-line @typescript-eslint/no-empty-function beforeEach(() => { }); afterEach(async () => { if (browser) { await browser.close(); browser = undefined; } }); test('should throw when selector is undefined - chromium', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); await (0, dom_actions_1.showMousePosition)(page); const url = `file:${path.join(__dirname, 'hover-on-handle.test.html')}`; await page.goto(url); const options = { ...hover_on_handle_1.defaultHoverOptions, timeoutInMilliseconds: 1000, }; // When // Then const expectedError = new Error("Cannot hover on 'foobar' because selector was not found in DOM"); await SUT.hoverOnHandle(undefined, 'foobar', page, options).catch((error) => expect(error).toMatchObject(expectedError)); }); test('should throw when selector is null - chromium', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); await (0, dom_actions_1.showMousePosition)(page); const url = `file:${path.join(__dirname, 'hover-on-handle.test.html')}`; await page.goto(url); const options = { ...hover_on_handle_1.defaultHoverOptions, timeoutInMilliseconds: 1000, }; // When // Then const expectedError = new Error("Cannot hover on 'foobar' because selector was not found in DOM"); await SUT.hoverOnHandle(null, 'foobar', page, options).catch((error) => expect(error).toMatchObject(expectedError)); }); test('should throw when no browser has been launched', async () => { // Given const page = undefined; const options = { ...hover_on_handle_1.defaultHoverOptions, timeoutInMilliseconds: 1000, }; // When // Then const expectedError = new Error("Cannot hover on 'foobar' because no browser has been launched"); await SUT.hoverOnHandle(null, 'foobar', page, options).catch((error) => expect(error).toMatchObject(expectedError)); }); });